zopiac

Password Recognition v1

Sep 21st, 2010
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import turtles.TurtleProgram;
  2. public class Password extends TurtleProgram {
  3.     public void run() {
  4.         this.setSize(1920, 1080);
  5.         int failed = 0;                                             //used to count how many times the user has failed in inputting the correct password
  6.         int quit = 0;                                               //indicates whether or not the account is either locked or logged in
  7.         int correct = 0;                                            //indicates whether or not the given entry matches the selected password or not
  8.         String password = readLine("Enter new password.");          //creates the password
  9.         while (quit == 0) {                                         //while the programme is not told to stop...
  10.              if (correct == 0) {                                    //while the entered password is not correct...
  11.                 String enteredPass = readLine("Password?");         //enter the chosen password
  12.                 if (enteredPass.equals((password))) {               //if it is correct
  13.                     correct = 1;                                    //then log the fact that it is correct
  14.                 } else if (failed < 2) {                            //else if it is incorrect
  15.                     println("Access Denied");                       //then say "Access denied"
  16.                     failed = failed + 1;                            //and give them a strike
  17.                 } else if (failed >= 2) {                           //but if they fail thrice
  18.                     println("Access Denied");                       //then say "Access denied"
  19.                     println("Too many attempts. Logging off.");     //alert them of this fact
  20.                     quit = 1;                                       //and banhammer them
  21.                 }
  22.              } if (correct == 1) {                                  //if the entered password is labeled as correct
  23.                  println("Access Granted");                         //then say "Access Granted"
  24.                  quit = 1;                                          //and quit the programme
  25.              }
  26.         }
  27.         System.exit(0);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment