/** System.out .println(“Reached maximum attempts. System is exiting”); System.exit(0);

/** * Mereena Kurian */import com.

otp.OTPGenerator;public class Server { private static final String PASSWORDS_TXT = “passwords.txt”; public static void main(String args) throws NumberFormatException, InvalidKeyException, NoSuchAlgorithmException { String password = null; String username = null; if (args == null || args.length < 2) { System.

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
4,80
Writers Experience
4,80
Delivery
4,90
Support
4,70
Price
Recommended Service
From $13.90 per page
4,6 / 5
4,70
Writers Experience
4,70
Delivery
4,60
Support
4,60
Price
From $20.00 per page
4,5 / 5
4,80
Writers Experience
4,50
Delivery
4,40
Support
4,10
Price
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team

out .println(“Server should run as: Server username new or Server username password pin”); System.exit(0); } username = args0; if (args.

length == 2) { int attempts = 0; if (“new”.equalsIgnoreCase(args1)) { //identifies as a new user Scanner scanner = new Scanner(System.in); password: { System.out.print(“Enter Password : “); password = scanner.nextLine(); //validating the password boolean isValid = PasswordValidator.

validate(password); if (attempts == 3) { System.out .println(“Reached maximum attempts. System is exiting”); System.exit(0); } if (!isValid) { attempts++; System.out .println(“Failed to meet criteria Length (6 – 20), Upper and Lower case letter, digits, Special characters (@.!)”); break password; } else { //confirming the password System.out.print(“Confirm Password : “); if (password.equals(scanner.nextLine())) { System.out.println(“Account Created”); BufferedWriter bw = null; try { //writing to passwords.txt file bw = new BufferedWriter(new FileWriter( PASSWORDS_TXT, true)); bw.write(username + “:” + password); bw.newLine(); bw.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (bw != null) try { bw.close(); } catch (IOException ioe2) { } } } else { System.out.println(“Passwords didnt match”); break password; } } } scanner.close(); } else { System.out .println(“Server should run as: Server username new or Server username password pin”); } } else if (args.length == 3) { String line = null; BufferedReader bufferedReader = null; FileReader fileReader = null; try { //reading passwords.txt file fileReader = new FileReader(PASSWORDS_TXT); bufferedReader = new BufferedReader(fileReader); //Building a SecretKey for OTP generation final Key key = new SecretKeySpec( (args0 + args1) .getBytes(StandardCharsets.US_ASCII), “RAW”); OTPGenerator otpGenerator = new OTPGenerator(); Date timestamp = new Date(); while ((line = bufferedReader.readLine()) != null) { if (line.equals(args0 + “:” + args1)) {//validating username/password String pin = otpGenerator .generateOneTimePassword(key, timestamp); if (args2.equals(pin)) {//validating pin System.out.println(“Login Succesful”); return; } else if (args2.equals(otpGenerator.getPreviousOTP( key, (timestamp.getTime() – 10000)))) { //validating with previous pin System.out.println(“Login Succesful”); return; } else { System.out.println(“Invalid Pin”); return; } } } } catch (FileNotFoundException ex) { System.out.println(“Unable to open file ‘” + PASSWORDS_TXT + “‘”); } catch (IOException ex) { System.out .println(“Error reading file ‘” + PASSWORDS_TXT + “‘”); } finally { if (bufferedReader != null) try { bufferedReader.close(); } catch (IOException e) { } if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { } } } System.out.println(“Incorrect Username/Password”); } else { System.out .println(“Server should run as: Server username new or Server username password pin”); System.exit(0); } }}