Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class ZooLogin extends ParseFile {
  2.  
  3. private String userName;
  4.  
  5. private String[] passWord;
  6. private MessageDigest md;
  7. private String original;
  8. private static boolean isTrue;
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. public static void main(String[] args) {
  12.  
  13.  
  14. boolean authenticateMe;
  15. ZooLogin log1 = new ZooLogin();
  16. log1.loginAuthentication(isTrue);
  17.  
  18.  
  19.  
  20. }
  21.  
  22. private boolean loginAuthentication(boolean isTrue) {
  23. //Begin login prompt
  24. System.out.println("Username: ");
  25. userName = sc.nextLine();
  26. //Hash password
  27. System.out.println("Password: ");
  28. original = sc.nextLine();
  29. getMD5Hash(original);
  30. ParseFile login = new ParseFile();
  31.  
  32. int i = 1;
  33.  
  34. while (i <= 3) {
  35. if (login.equals(original)) {
  36. isTrue = true;
  37. }
  38. else {
  39. i++;
  40. }
  41.  
  42. }
  43.  
  44. return isTrue;
  45. }
  46.  
  47. public String getMD5Hash(String[] original) {
  48.  
  49. try {
  50. md = MessageDigest.getInstance("MD5");
  51. } catch (NoSuchAlgorithmException ex) {
  52. }
  53. md.update(original.getBytes());
  54. byte[] digest = md.digest();
  55. StringBuffer sb = new StringBuffer();
  56. for (byte b : digest) {
  57. sb.append(String.format("%02x", b & 0xff));
  58. }
  59.  
  60. return sb.toString();
  61. }
  62.  
  63. public class ParseFile {
  64.  
  65. public String line;
  66. public String c1;
  67.  
  68. public String ParseFile(String[] args) throws FileNotFoundException {
  69.  
  70. ParseFile compare = new ParseFile();
  71. //creating file instance to parse text from credentials file
  72. File text = new File("src\ZooLogin\credentials.txt");
  73.  
  74. //creating scanner isntance to input text from file
  75. Scanner sc = new Scanner(text);
  76.  
  77.  
  78. int lineNumber = 1;
  79. int stringLoc1 = 0;
  80. int stringLoc2 = 0;
  81.  
  82. while(sc.hasNextLine()) {
  83. line = sc.nextLine();
  84. }
  85.  
  86.  
  87. return line;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement