I'm new to java and writing a program that accepts user input for a password and it has to meet the following requirements:
1. At least 6 characters long.
2. Leading character can't be a digit.
3. Password must have at least 1 digit.
4. Password must have at least 1 upper case letter.
The main method will keep asking the user for a password (using a while loop) until it gets one that's okay.
The other method has the signature:
public static boolean checkPassword (String word)
How do I write the while loop and checkPassword? PLEASE HELP!
- import java.util.Scanner;
-
-
public class Password
-
{
-
public static void main (String[] args)
-
{
-
Scanner input;
-
-
input = new java.util.Scanner(System.in);
-
-
String pword = "";
-
boolean checkPassword;
-
-
System.out.print("Please enter a new password:");
-
pword = input.nextLine();
-
while (checkPassword == false);
-
{
-
System.out.println("Your password does not meet the requirements!");
-
-
}}
-
public static boolean checkPassword (String pword)
-
{
-
boolean bHasNUmeric = false;
-
boolean bHasUpper = false;
-
-
-
Your while loop may led to infinite loop if checkPassword sets to false....
and also you have checkPassword method... Have you read your book?
Maybe you forgot it to implement it in the rightway.... Java is case sensitive...
Semicolon after while( \\\\\ ) is not necessary....
You are not initializing the Scanner to what stream shall it going to use for having the input value....
- Scanner input = new Scanner(System.in);
Please, read carefully your book.... Doing so may avoid this kind of confusions....
Base on your code...
It prompts the user for password, since the condition might always true... You have to change the checkPassword into true if the input will be satisfied...
Here is the algo....
While ( Password is not satisfied ){
Prompt the user for password...
Check if it is allowable....
Compare the user's input to your choosen password.
If satisfied
Let the Password be satisfied
}
Update us,
sukatoa