Question: Question: Password Checking Software to reset passwords often requires the user to enter the password twice, checking to make sure it was entered the same
Question:
Password Checking Software to reset passwords often requires the user to enter the password twice, checking to make sure it was entered the same way both times. Write a method in Java that can verify that the two passwords entered are correct. . Your project should contain a method that ask the user to enter a password twice, then either tell the user that the two entries were not the same and start the process over again, or, if they are the same, tell the user that the new password was accepted.
Additionally, the user is required to enter in a password that meets specific security requirements.
Proper Passwords are required to follow the these rules:
The password must be at least 8 characters long.
The password must contain at least: - one alpha character [a-zA-Z]; - one numeric character [0-9]; - one character that is not alpha or numeric, such as but not limited to the following ! # @ $ % ^ & * ( ) - _ = + [ ] ; : ' " , < . > / ?
- This means that the application should verify for any special character
The password must not: - contain spaces; - begin with an exclamation [!] or a question mark [?];
The password cannot contain repeating character strings of 3 or more identical characters, such as 111 or aaa.
Your task is to create a project to verify whether or not a prospective proper password meets these requirements and that the user has entered the correct password in twice. My Problem in coding this:
- The password must not contain spaces;
- The password cannot contain repeating character strings of 3 or more identical characters, such as 111 or aaa.
Code so far: package strings.programming;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;
/** * * @author */ public class StringsProgramming { private String password; public StringsProgramming(String password) { this.password = password; } String verifyPassword() { boolean hasAlpha, hasNum, hasSpecial; hasAlpha = hasNum = hasSpecial = false; int len = password.length(); if (len < 8) return "Your password must contain atleast 8 characters"; if (password.charAt(0) == '!' || password.charAt(0) == '?') return "You password cannot begin with ? or !"; for (int i = 0; i < len; i++) { char ch = password.charAt(i); if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) hasAlpha = true; else if (ch >= '0' && ch <= '9') hasNum = true; else hasSpecial = true; } if (!hasAlpha || !hasNum || !hasSpecial) return "You password must contain " + "atleast 1 alphabet " + "atleast 1 numeric character " + "atleast 1 special character"; return null; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String passString = null; do { do { System.out.println("Please enter your Password: "); passString = br.readLine(); System.out.println("Please re-enter your Password to confirm: "); String cnfPassString = br.readLine(); if (!passString.equals(cnfPassString)) { System.out.println("The two passwords that you have entered does not match"); passString = null; } }while (passString == null); StringsProgramming p = new StringsProgramming(passString); String report = p.verifyPassword(); if (report != null) System.out.println(report); else { System.out.println("The password you have entered is valid"); break; } }while (true); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
