Skip to content

Instantly share code, notes, and snippets.

@justinrolston
Created May 21, 2011 11:16
Show Gist options
  • Save justinrolston/984447 to your computer and use it in GitHub Desktop.
Save justinrolston/984447 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Unit8Project
{
public static void main (String[] args)
{
String apassword1;
String apassword2;
Scanner keyboard = new Scanner(System.in);
boolean done = false;
while (done == true)
{
System.out.print("Enter a password: ");
apassword1 = keyboard.nextLine();
if(ValidateLength(apassword1) && ValidateChars(apassword1))
{
System.out.print("Re-enter your password: ");
apassword2 = keyboard.nextLine();
if (apassword1.equals(apassword2))
{
done = true;
System.out.print("You have successfully created a password");
}
else
{
System.out.print("The password you entered is invalid, please try again");
}
}
else
{
System.out.print("The password you entered does not match, please try again");
}
}
}
private boolean ValidateLength(string pwd)
{
return (pwd.length() >= 6);
}
private boolean ValidateChars(string pwd)
{
return (pwd.matches(".*[a-zA-Z]+.*") && pwd.matches(".*[0-9].*"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment