Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtles.TurtleProgram;
- public class Password extends TurtleProgram {
- public void run() {
- this.setSize(1920, 1080);
- int failed = 0; //used to count how many times the user has failed in inputting the correct password
- int quit = 0; //indicates whether or not the account is either locked or logged in
- int correct = 0; //indicates whether or not the given entry matches the selected password or not
- String password = readLine("Enter new password."); //creates the password
- while (quit == 0) { //while the programme is not told to stop...
- if (correct == 0) { //while the entered password is not correct...
- String enteredPass = readLine("Password?"); //enter the chosen password
- if (enteredPass.equals((password))) { //if it is correct
- correct = 1; //then log the fact that it is correct
- } else if (failed < 2) { //else if it is incorrect
- println("Access Denied"); //then say "Access denied"
- failed = failed + 1; //and give them a strike
- } else if (failed >= 2) { //but if they fail thrice
- println("Access Denied"); //then say "Access denied"
- println("Too many attempts. Logging off."); //alert them of this fact
- quit = 1; //and banhammer them
- }
- } if (correct == 1) { //if the entered password is labeled as correct
- println("Access Granted"); //then say "Access Granted"
- quit = 1; //and quit the programme
- }
- }
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment