Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. package it145finalproject;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.security.MessageDigest;
  6. import java.security.NoSuchAlgorithmException;
  7. import java.util.Scanner;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11.  
  12. public class IT145FinalProject {
  13.  
  14.  
  15. public static void main(String[] args) {
  16. Scanner scnr = new Scanner(System.in);
  17. int loginAttempts = 0;
  18. String userName;
  19. String userPass;
  20. FileInputStream inCredentials = null;
  21. FileInputStream inAdmin = null;
  22. FileInputStream inVeterinarian = null;
  23. FileInputStream inZookeeper = null;
  24. Scanner inCreds = null;
  25. Scanner inAd = null;
  26. Scanner inVet = null;
  27. Scanner inZoo = null;
  28. String fileName = "";
  29. String fileHash = "";
  30. String filePass = "";
  31. String fileLevel = "";
  32.  
  33.  
  34. try {
  35. inCredentials = new FileInputStream("credentials.txt");
  36. } catch (FileNotFoundException ex) {
  37. Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
  38. }
  39. inCreds = new Scanner(inCredentials);
  40.  
  41. try {
  42. inAdmin = new FileInputStream("admin.txt");
  43. } catch
  44. (FileNotFoundException ex) {
  45. Logger.getLogger(IT145FinalProject.class.getName()).log (Level.SEVERE, null, ex);
  46. }
  47. inAd = new Scanner(inAdmin);
  48.  
  49. try {
  50. inVeterinarian = new FileInputStream("veterinarian.txt");
  51. } catch (FileNotFoundException ex) {
  52. Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
  53. }
  54. inVet = new Scanner(inVeterinarian);
  55.  
  56. try {
  57. inZookeeper = new FileInputStream("zookeeper.txt");
  58. } catch (FileNotFoundException ex) {
  59. Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
  60. }
  61. inZoo = new Scanner(inZookeeper);
  62.  
  63.  
  64.  
  65.  
  66. System.out.println("Enter username: ");
  67. userName = scnr.next();
  68.  
  69. System.out.println("Enter password: ");
  70. userPass = scnr.next();
  71.  
  72. while (loginAttempts < 3) {
  73. String original = userPass; //Replace "password" with the actual password inputted by the user
  74. MessageDigest md = null;
  75. try {
  76. md = MessageDigest.getInstance("MD5");
  77. } catch (NoSuchAlgorithmException ex) {
  78. Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
  79. }
  80. md.update(original.getBytes());
  81. byte[] digest = md.digest();
  82. StringBuffer sb = new StringBuffer();
  83. for (byte b : digest) {
  84. sb.append(String.format("%02x", b & 0xff));
  85. }
  86. fileName = inCreds.next();
  87. fileHash = inCreds.next();
  88. filePass = inCreds.next();
  89. fileLevel = inCreds.next();
  90.  
  91. while (userName.equals(fileName)) {
  92. while (userPass.equals(filePass)) {
  93. if (fileLevel.equals("zookeeper")){
  94. System.out.print(inZoo);
  95. }
  96. else if (fileLevel.equals("admin")){
  97. System.out.print(inAd);
  98. }
  99. else if (fileLevel.equals("veterinarian")){
  100. System.out.print(inVet);
  101. }
  102.  
  103. }
  104. }
  105. loginAttempts++;
  106. }
  107.  
  108.  
  109.  
  110. }
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement