Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package projekt1;
  2. import java.util.*;
  3.  
  4. public class AccessControl2 {
  5. public static Scanner scan = new Scanner(System.in);
  6. public static String username = "";
  7. public static String password = "";
  8. public static void main(String[] args) {
  9. username();
  10. passwordChange();
  11. while(true) {
  12. System.out.println("You now have the following choices :\r\n" +
  13. "1 - Change Password\r\n" +
  14. "2 - Log off\r\n" +
  15. "3 - Shut down");
  16. System.out.print("Please select :");
  17. int choice = scan.nextInt();
  18. if (choice == 1) {
  19. passwordChange();
  20. }
  21. if (choice == 2) {
  22. System.out.println("*** User" + username + "is logged off");
  23. while(true) {
  24. System.out.print("To logon enter username :");
  25. String musername = scan.nextLine();
  26. if (username.equals(musername)) {
  27. break;
  28. }
  29. }
  30. int t = 3;
  31. while (t >= 0) {
  32. t--;
  33. System.out.println("To logon enter password :");
  34. String mpassword = scan.nextLine();
  35. if (password.equals(mpassword)) {
  36. System.out.println("*** User Otto is Logged on .");
  37. break;
  38. }
  39. if (t == 0 ) {
  40. System.exit(0);
  41. }
  42. }
  43. }
  44.  
  45. if (choice == 3) {
  46. System.out.println("*** User" + username + " is logged off");
  47. System.out.println("*** System shutting down .");
  48. System.exit(0);
  49. }
  50. }
  51. }
  52. public static String username() {
  53. while(true) {
  54. System.out.print("Please enter a non - empty username :");
  55. String username = scan.next();
  56. if (Character.isUpperCase(username.charAt(0)) && !username.contains(" ")) {
  57. return username;
  58. }
  59. }
  60. }
  61. // Change/Create password
  62. public static String passwordChange() {
  63. while(true) {
  64.  
  65. String password = scan.nextLine();
  66. if (john.checkPWD(password)) {
  67. System.out.print("Please repeat the password :");
  68. String onePassword = scan.nextLine();
  69. if (john.checkPWD(onePassword) == true && onePassword.equals(password)) {
  70. return password;
  71. }
  72. }
  73. System.out.print("Please enter a password :");
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement