How does sudo remember you already entered root's password?

Attempting to create a Java password program?

  • Java program that asks for user input of a password that must be between 6 and 10 characters and must contain at least one digit and one letter. So far I am having problems remember how to check if a digit or char is present and struggling with my while loops to continue if the users passwords don't match any help will be greatly appreciated. import java.util.Scanner; public class PasswordCreator{ public static void main(String[]args){ Scanner input = new Scanner(System.in); int digit = 0; int letter = 0; String password,verifyPassword; System.out.println("Please enter an password"); password=input.nextLine(); while(password.length()<6 || password.length()>10) { System.out.println("Password must be between 6 and 10 characters please re-enter"); password=input.nextLine(); } System.out.println("Password you entered in valid please re-enter to confirm"); verifyPassword=input.nextLine(); while(verifyPassword.equals(password… { System.out.println("Your passwords match Thank You!"); } } }

  • Answer:

    first of all change while(verifyPassword.equals(password)) { System.out.println("Your passwords match Thank You!"); } to while( ! verifyPassword.equals(password) ) { System.out.println("Passwords not matching. please re-enter"); verifyPassword=input.nextLine(); } System.out.println("Your passwords match Thank You!"); Now.. checking for presence of a char or digit. better earn and use regular expressions. ok..i will put a trail code here.. ok add this statement to your program String pattern = "(\\w+)((\\d+)(\\w+))"; now modify while(password.length()<6 || password.length()>10) to while(password.length()<6 || password.length()>10 || !password.matches(pattern)) now your program will accept passwords containing alphabets and digits only

Lucas at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.