Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projekt1;
- import java.util.*;
- public class AccessControl2 {
- public static Scanner scan = new Scanner(System.in);
- public static String username = "";
- public static String password = "";
- public static void main(String[] args) {
- username();
- passwordChange();
- while(true) {
- System.out.println("You now have the following choices :\r\n" +
- "1 - Change Password\r\n" +
- "2 - Log off\r\n" +
- "3 - Shut down");
- System.out.print("Please select :");
- int choice = scan.nextInt();
- if (choice == 1) {
- passwordChange();
- }
- if (choice == 2) {
- System.out.println("*** User" + username + "is logged off");
- while(true) {
- System.out.print("To logon enter username :");
- String musername = scan.nextLine();
- if (username.equals(musername)) {
- break;
- }
- }
- int t = 3;
- while (t >= 0) {
- t--;
- System.out.println("To logon enter password :");
- String mpassword = scan.nextLine();
- if (password.equals(mpassword)) {
- System.out.println("*** User Otto is Logged on .");
- break;
- }
- if (t == 0 ) {
- System.exit(0);
- }
- }
- }
- if (choice == 3) {
- System.out.println("*** User" + username + " is logged off");
- System.out.println("*** System shutting down .");
- System.exit(0);
- }
- }
- }
- public static String username() {
- while(true) {
- System.out.print("Please enter a non - empty username :");
- String username = scan.next();
- if (Character.isUpperCase(username.charAt(0)) && !username.contains(" ")) {
- return username;
- }
- }
- }
- // Change/Create password
- public static String passwordChange() {
- while(true) {
- String password = scan.nextLine();
- if (john.checkPWD(password)) {
- System.out.print("Please repeat the password :");
- String onePassword = scan.nextLine();
- if (john.checkPWD(onePassword) == true && onePassword.equals(password)) {
- return password;
- }
- }
- System.out.print("Please enter a password :");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement