Implement a program that reads in a user password

Assignment Help JAVA Programming
Reference no: EM131565915

I would like to make this program continue looping until a valid password is entered. While this isn't required I still think its needed.

Requirements
Main Method
Implement a program that reads in a user password and verifies it meets the following criteria:
Is at least 8 characters long
Contains at least 1 lower letter character
Contains at least 1 upper letter character
Contains at least 1 numeric digit
Contains at least 1 special character from the set: !@#$%^&*
Does not contain the word "and" or the word "end"
Output a string that prompts the user for a password and include the requirements above in your output.
Output a string that states valid or invalid. If invalid, state which rule above has not been met.
Utilize the following functionality:
indexOf
Looping structure
charAt()
isDigit()
isUpperCase()
isLowerCase()
? and any additional functionality needed.


Code so far
import java.util.Scanner;
public class Project2
{
public static void main(String args[]){
String password;
int len, upper = 0, lower = 0, number = 0, charac = 0, i;
boolean substr;
Scanner in = new Scanner(System.in);
System.out.println("Enter a password that meets the following rules:n" +
"1. Is at least 8 characters longn" +
"2. Contains at least 1 lower letter charactern" +
"3. Contains at least 1 upper letter charactern" +
"4. Contains at least 1 numeric digitn" +
"5. Contains at least 1 special character from the set: !@#$%^&*n" +
"6. Does not contain the word and or the word endn");
System.out.print ("Password: ");
password = in.next();
len = password.length();
for(i = 0; i < len; i++){
char x = password.charAt(i);
if(Character.isUpperCase(x)) upper++;
if(Character.isLowerCase(x)) lower++;
if(Character.isDigit(x)) number++;
if(x == '!' || x == '@' || x == '#' || x == '

|| x == '%' || x == '^' || x == '&' || x == '*') charac++;

 

}
if(password.indexOf("and") == 1 || password.indexOf("end") == 1) substr = false;
else substr = true;
if(len < 8 || upper < 1 || lower < 1 || number < 1 || charac < 1 || substr == false)

{
System.out.println("Invalid!!");
if(len < 8) System.out.println("Must be at least 8 characters long.");
if(upper < 1) System.out.println("There should be atleast 1 uppercase character.");
if(lower < 1) System.out.println("There should be atleast 1 lowercase character.");
if(number < 1) System.out.println("Must contain a numeric digit");
if(charac < 1) System.out.println("Missing a special character");
if(substr == false) System.out.print("The password should not contain the word "and" or "end".");
}
else System.out.println("Valid!!");
}
}

Reference no: EM131565915

Questions Cloud

Calculate the net benefit of outsourcing : Outsourcing (Make-or-Buy) Decision - Calculate the net benefit (cost) of outsourcing the electric motors from Mini Motor Company
Describe the role and purpose of statistics : Describe the role and purpose of statistics. Explain the primary types of statistics. Contrast a population and a sample.
Class that displays your favorite movie quote : Write, compile, and test a class that displays your favorite movie quote, the movie it comes from, the character who said it, and the year of the movie.
How a criminal justice manager could have a positive impact : Write a 250 to 500 word essay on how a criminal justice manager could have a positive impact on the police culture and improve police/community relations.
Implement a program that reads in a user password : Program continue looping until a valid password is entered. While this isn't required I still think its needed.
Examine the food labels for three food items : Outline how the 5/20 rule would be applied to at least two chronic diseases. For the diseases mentioned which nutrients should be reduced or increased?
Explain why titanium is a good choice of material for golf : Explain why titanium is a good choice of material for golf clubs. When not in use, discuss at least one precaution to observe when storing clubs?
Calculate the dollar cost of goods available for sale : REI carries the "Desert Rat' hiking boot whose sales are directed at Sonoran desert areas such as Arizona. Compute gross profit for each of the costing methods
What can america learn from japan : The Japanese experience demonstrates the importance of cultural issues, such as caring and sharing, that profoundly influence health outcomes.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd