Allan Didier

Password Checker

Goals

Write a Java program that can check the validity of a password.

Skills

  • Strings
  • While loops

Program Details

Write an application that

  1. Asks the user to enter the following case sensitive information:
    1. their first name
    2. last name
    3. username
    4. password. A password can have letters, numbers, or other characters.
  2. Checks to see if their password is valid. A password is invalid if:
    1. It is less than 8 characters long.
    2. It contains their first name, last name or user name.
    3. Ignore the case when checking. Don’t change the case of the first, last, or username, just ignore the case when checking.
  3. If the password fails, ask the user to choose another password until they enter a valid password.
  4. Output all values upon a successful password choice.

Test the program with

  1. passwords less than 8 characters
  2. passwords containing the first. last and user names.
  3. passwords with numbers as well as characters

Hints:

  • Make sure your output makes sense to someone running the program.
  • Use a different string variable for each item (first name, last name, …).
  • Only ignore case when checking validity. Don’t just drop the case when scanning them in. 
  • The following string methods will help.
    • string.length() returns the length of the string.
    • string1.contains(string2) returns a boolean if the string1 contains string2 in it.
    • string.toLowerCase() returns a lower case version of the string.

Resources

Java Textbook

Chapter 3: Using Classes and Objects

Chapter 5: Conditionals and Loops

CS Awesome Website

Bill Barnum's AP Computer Science A videos