Directions Weight The file must be called Example: DeweyKenProg5.java Ensure you
ID: 3528717 • Letter: D
Question
Directions Weight The file must be called Example: DeweyKenProg5.java Ensure you include ALL files required to make your program compile and run. I would like to see your .java files only. Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter. Main Method Implement a program that reads in a user password and verifies it meets the following criteria: Is atleast 8 characters long Contains atleast 1 lower letter character Contains atleast 1 upper letter character Contains atleast 1 numeric digit Contains atleast 1 special character from the set: !@#$%^&* Does not contain the wordExplanation / Answer
import java.io.Console; import java.util.Arrays; import java.io.IOException; public class Password { public static void main (String args[]) throws IOException { Console c = System.console(); if (c == null) { System.err.println("No console."); System.exit(1); } String login = c.readLine("Enter your login: "); char [] oldPassword = c.readPassword("Enter your old password: "); if (verify(login, oldPassword)) { boolean noMatch; do { char [] newPassword1 = c.readPassword("Enter your new password: "); char [] newPassword2 = c.readPassword("Enter new password again: "); noMatch = ! Arrays.equals(newPassword1, newPassword2); if (noMatch) { c.format("Passwords don't match. Try again.%n"); } else { change(login, newPassword1); c.format("Password for %s changed.%n", login); } Arrays.fill(newPassword1, ' '); Arrays.fill(newPassword2, ' '); } while (noMatch); } Arrays.fill(oldPassword, ' '); } // Dummy change method. static boolean verify(String login, char[] password) { // This method always returns // true in this example. // Modify this method to verify // password according to your rules. return true; } // Dummy change method. static void change(String login, char[] password) { // Modify this method to change // password according to your rules. } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.