UNIVERSITY OF MARYLAND DEPARTMENT OF COMPUTER SCIENCE CMSC131 - Object-Oriented Programming I Section 010x and 030x Dr. Ilchul Yoon Project 4 Password Checker and Generator Assigned: Mar. 27th, 2019...

1 answer below »
Java: Introduction to Object Oriented


UNIVERSITY OF MARYLAND DEPARTMENT OF COMPUTER SCIENCE CMSC131 - Object-Oriented Programming I Section 010x and 030x Dr. Ilchul Yoon Project 4 Password Checker and Generator Assigned: Mar. 27th, 2019 Due: Apr. 8th, 2019 11:00 PM Late Due: Apr. 9th, 2019 11:00 PM — 15% penalty Good Faith Attempt Due: One week after grades are published. 1 Overview In this project, you will implement a password checker and generator in Java. The main objective of this project is to reinforce your understanding on the String class. You must use Eclipse to work on this project. Download first a file p4-starter.zip from Canvas (CMSC131 > Files > projects > cmsc131-project-4) and import into Eclipse. Then, complete the methods in the classes: CheckPasswords and PasswordGenerator. If you need, you can write additional methods in the classes, but you must not modify the header of the methods already given in the class files. 2 Requirements The following are the password rules used by a web site: • A password must be at least 8 and no more than 32 characters in length. • A password must contain at least one character from each of the following sets: – Uppercase alphabet (A-Z) – Lowercase alphabet (a-z) – Numbers (0-9) OR special characters (such as # @ $ &) – i.e., a password without any special character can be a valid password if it has at least one digit, and vice versa. • A password may not begin or end with the space character. • A password may not contain more than two consecutive identical characters. • A password may not be (or be a variation of ) a dictionary word in English or many other languages. This includes making simple substitutions of digits or punctuation that resemble alphabetic characters. In specific, 0 (for o), 1 (for l), and $ (for s). • The length of the password is at least 5 characters longer than a dictionary word. • Passwords should not contain: carriage return (ASCII 13, ‘\r’), linefeed (ASCII 10, ‘\f’), /, \, or a trailing * symbol). You will complete the following methods in CheckPasswords.java: • static int countUppercaseLetters(String password) Count the number of uppercase letters in password and returns the count; can assume only ASCII characters. Returns the number of upper case letters. For example, if password is ABC2928fh, it returns 3. • static int countLowercaseLetters(String password) Count the number of lowercase letters in password and returns the count; can assume only ASCII characters. For example, if password is ABC2928fh, it returns 2. • static int longestConsecutiveIdenticalCharacters(String password) Count the longest sequences of consecutive identical characters; can assume only ASCII characters. Returns the maximum repeat count. For example, given the password helloworld, this method returns 2. Similarly, for aabaaaahd, it returns 4. • static boolean similarToWord(String word, String password) Check to see if a password is to similar to a dictionary word. It is too similar if the dictionary word (the first parameter) is contained in the password (the second parameter) when ignoring case and treating ‘1’ and ‘l’ as identical , ‘o’ and ‘0’ as identical, and ‘s’ and ‘$’ as identical, and the length of the password should be at least 5 characters longer than the word. Otherwise, they are considered similar. For example, if galaxy is the value of word and galaxy1234 is the value of password, this method returns true, but it returns false for galaxy12345. • static boolean checkPassword(String password, String[] dictionary) Check to see if password, given as a parameter, conforms to the password rules described above. It returns false if the password does not conform to any of the rules. Otherwise it returns true. You will also complete the following method in PasswordGenerator.java: 1 • static String generatePassword(int wordCount, Random r, String[] words) Generate a password from the list of words provided. The password should be concatenation of wordCount number of words, and no word should be repeated more than once. There are several ways to ensure that no word is used more than once. The simplest is, as you generate a candidate word to be appended to the password being generated, to ensure that it isn’t already contained in what has already been generated. There is no need to check that the password satisfies the UMD password restrictions, or any of the conditions checked by CheckPassword. All random numbers should be generated using the supplied Random object r. This will allow for deterministic testing. 3 Other Requirements Follow a good coding style (e.g., http://www.cs.umd.edu/~nelson/classes/resources/javastyleguide/. You are expected to use meaningful variable names, to format your code well (use the Source > Format menu in Eclipse for automatic format), and to document your code properly. You are required to write your name, directory ID, university ID, and section number as a comment at the top of each Java file. You are also required to put comments in your code too! Your code should be readable with appropriate comments, and you will need to use meaningful variable names. Good use of variables, rather than “magic numbers” (literal constants) is mandatory. There are no explicit requirements for how many and what type of variables. For readability including variable naming, we suggest you to use these rules: • Format the code clearly with blank lines, spacing and indents • Use self-documenting, meaningful variable names • Use variable names that begin with lower case and then camel case ( e.g., roomTemp ) if two words • Use capital letters (e.g., ALL CAPS ) for variables that encodes constant values that aren’t updated • Use appropriate comments that indicate what a section, or a complicated line, does Additionally, we expect you to write the honor pledge (I pledge on my honor that I have not given or received any unauthorized assistance on this assignment/examination.) as a comment near the top of each Java file you submit. 4 Submission and Grading Submit your work to P4 in the submit server by the due date/time (Check the submit server). It is strongly recommended to submit directly using the ‘Submit Project’ menu in Eclipse. After submission, check in the submit server that your work is submitted correctly and also that your code passed all tests. Your work will be evaluated by running test cases against your code. There are three test sets – public tests, release tests, and secret tests. You must pass all public/release/secret tests for receiving the full credits. Every time you submit your code, the submit server will test the code against the public tests and will show test results in a table. Once you passes all public tests, you will see a “Perform Release Test” button in the submit server. Note that the release test can be run only 3 times a day and also that only 2 failed tests will be displayed in the result table. 5 Good Faith Attempt Policy for Projects Your work must pass 12 out of 17 public tests. 2 http://www.cs.umd.edu/~nelson/classes/resources/javastyleguide/ 6 Academic Integrity Make sure you read the academic integrity section of the syllabus so you understand what you must not do. Note that we check your submission against other students’ submissions and that we are required to report academic dishonesty cases to the University’s Office of Student Conduct. As stated in Section 3, you are expected to write the honor pledge as a comment near the top of each file you submit. 3 Overview Requirements Other Requirements Submission and Grading Good Faith Attempt Policy for Projects Academic Integrity
Answered Same DayApr 06, 2021

Answer To: UNIVERSITY OF MARYLAND DEPARTMENT OF COMPUTER SCIENCE CMSC131 - Object-Oriented Programming I...

Aditi answered on Apr 09 2021
134 Votes
Solution/CheckPasswords.java
Solution/CheckPasswords.java
public class CheckPasswords {
    static int countUppercaseLetters(String password) {
        int count = 0;
        for (int i = 0; i < password.length(); i++) {       //iterate over each character in password
            if (password.charAt(i) >= 'A' && password.charAt(i) <= 'Z') { 
//check is charatcer is in uppercase
                count++;        //increment count
            }
        }
        return count;
    }
    static int countLowercaseLetters(String password) {
        int count = 0;
        for (int i = 0; i < password.length(); i++) {       //iterate over each character in password
            if (password.charAt(i) >= 'a' && password.charAt(i) <= 'z') {        //check is charatcer is in lowercase
                count++;        //increment count
            }
        }
        return count;
    }
    static int longestConsecutiveIdenticalCharacters(String password) {
        if(password.length() == 0)      //check if password is empty
            return 0;
        int max = 1, count = 1;
        for (int i = 1; i < password.length(); i++) {       //iterate over each character in password
            if (password.charAt(i) == password.charAt(i - 1)) {     //compare current character with previou character
                count++;        //increment count
            } else {
                if (count > max) {          //current count is greater than max
                    max = count;
                }
                count = 1;
            }
        }
        return max;
    }
    static boolean similarToWord(String word, String password) {
        password = password.toLowerCase();          //convert word and password to lowercase to ignore case
        word = word.toLowerCase();
        password = password.replace('1', 'l').replace('0', 'o').replace('$', 's');      //replace 1,0 and $ as l,o and s

        if(password.contains(word) && password.length() - word.length() < 5)        //check if password contains word and difference of their length is less than 5
            return true;
        return false;
    }
    static boolean checkPassword(String password, String[] dictionary) {
        if(password.length() < 8 || password.length() > 32)     //check if password length is less than 8 or greater than 32
            return false;
        if(password.charAt(0) == ' ' || password.charAt(password.length()-1) == ' ')    //if password have trailing spaces
            return false;
        if(longestConsecutiveIdenticalCharacters(password) > 2)     //password have more than 2 consecutive characters
            return false;
        if(countLowercaseLetters(password) < 1 || countUppercaseLetters(password)< 1)       //password doesnt have any lowercase or uppercase character
            return false;

        boolean flag = false;
        for (int i = 0; i < password.length() && !flag; i++) {
            switch (password.charAt(i)) {           //check at least one special character must be present
                case '#':
                case '@':
                case '$':
                case '&':
                    flag = true;
            }
            if (password.charAt(i) >= '0' && password.charAt(i) <= '9') {   //at least one number must be present
                flag = true;
            }
        }
        if (!flag) {        //no special character and number is present
            return false;
        }
        for(i...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here