Esempio n. 1
0
 /*
  * authenticate
  * Will read user login file line by line until a username and passcode match is found
  * @argument String username to be compared with decrypted username from file
  * @argument String passcode to be compared with decrypted passcode from file
  * @return boolean true if passcode and username match, false otherwise
  * */
 public boolean authenticate(String szUsername, String szPasscode) throws IOException {
   Scanner scan = new Scanner(file);
   String[] szDec = null;
   boolean bRet = false;
   while (scan.hasNextLine()) {
     szDec = Xor.decrypt(scan.nextLine()).split(":");
     if (szDec[0].equals(szUsername) && szDec[1].equals(szPasscode)) bRet = true;
   }
   scan.close();
   return bRet;
 }
Esempio n. 2
0
 /*
  * doesUsernameExist
  * private Method only to be used by this class
  * Will prevent duplicate username accounts
  * @argument String username to be checked
  * @return boolean true if username exists in file, false otherwise
  * */
 private boolean doesUsernameExist(String szUsername) throws IOException {
   Scanner scan = new Scanner(file);
   String[] szDec = null;
   boolean bRet = false;
   while (scan.hasNextLine()) {
     szDec = Xor.decrypt(scan.nextLine()).split(":");
     if (szDec[0].equalsIgnoreCase(szUsername)) bRet = true;
   }
   scan.close();
   return bRet;
 }
Esempio n. 3
0
 /*
  * recover
  * Method will recover a password for the user provided the information matches accordingly
  * WIll be called from the RecoverFrame
  * @argument String username to be matched with file
  * @argument String passcode to be matched with file
  * @argument String email provided during registration, to be matched with file
  * @argument String security question used during registration, to be matched with file
  * @argument String security answer used during registration, to be matched with file
  * @return String passcode if all information provided matches accordingly with information in file, null otherwise
  * */
 public String recover(String szUsername, String szEmail, String szQuestion, String szAnswer)
     throws IOException {
   Scanner scan = new Scanner(file);
   String[] szDec = null;
   String szPasscode = null;
   while (scan.hasNextLine()) {
     szDec = Xor.decrypt(scan.nextLine()).split(":");
     if (szDec[0].equalsIgnoreCase(szUsername)
         && szDec[2].equalsIgnoreCase(szEmail)
         && szDec[3].equalsIgnoreCase(szQuestion)
         && szDec[4].equalsIgnoreCase(szAnswer)) szPasscode = szDec[1];
   }
   scan.close();
   return szPasscode;
 }
Esempio n. 4
0
 /*
  * buildEncryptedString
  * private helper method, can only be used by this class
  * Will combine arguments using : as delimeter then encrypt the strings
  * @argument String username to be Encrypted and written to file
  * @argument String passcode to be Encrypted and written to file
  * @argument String email to be Encrypted and written to file
  * @argument String security question to be Encrypted and written to file
  * @argument String security answer to be Encrypted and written to file
  * @return String Encrypted form
  * */
 private String buildEncryptedString(
     String szUsername, String szPasscode, String szEmail, String szQuestion, String szAnswer) {
   String szUserData =
       szUsername + ":" + szPasscode + ":" + szEmail + ":" + szQuestion + ":" + szAnswer;
   return Xor.encrypt(szUserData);
 }