My issue is this I have writen a password program but I need it to verify the password after it is entered correctly. heres the code I have
import java.util.Scanner;
public class Password
{
// Create main method
public static void main(String[] args)
{
// Declare variables
Scanner sc = new Scanner(System.in);
int letters = 0;
int digits = 0;
boolean goodPassword;
do
{
// Prompt user to enter a possible password
System.out.println("Please enter a possible password.");
String password = sc.nextLine();
int len = password.length(); // Determines the lenght of the password
// Check to see if the password contains at least one number and one letter
for (int i = 0; i < password.length(); ++i)
{
char c = password.charAt(i);
if (Character.isLetter(c))
++letters;
if (Character.isDigit(c))
++digits;
}
goodPassword = !(len < 6 || len > 10 || letters == 0 || digits == 0);
// Check to see that the password is 6 to 10 characters long, and contains 1 letter and 1 number.
if (len < 6 || len > 10 || letters == 0 || digits == 0)
System.out.println("Passwords must be 6 to 10 characters in lenght. Contain at least 1 letter, and 1 number. Please try again.");
else
System.out.println("Excepted. Please re-enter your password for verification.");
}
while (!goodPassword);
}
private Password()
{
}
}

New Topic/Question
Reply



MultiQuote







|