Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class PasswordClient { public static void main( String args [] ) { String input = ; Scanner read = new Scanner(System.in); System.out.println(Password.passwordCriteria);

import java.util.Scanner;

public class PasswordClient

{

public static void main( String args [] )

{

String input = "";

Scanner read = new Scanner(System.in);

System.out.println(Password.passwordCriteria);

while(true)

{

//reading user input

System.out.println("Enter password to test or quit to end ");

input = read.nextLine();

//break out of loop if user enters "quit"

if(input.equals("quit"))

{

break;

}

System.out.println(Password.validate(input));

}

}

}

/////////////////////////////////////////////////////

/////////////////////////////////////////////////////

public class Password

{

static final String passwordCriteria="Must contain a minimum of 8 characters. Must not contain spaces. Must contain at least one upper case letter. Must contain at least one lower case letter. Must contain at least one number or special character.";

public static String validate(String givenPassword)

{

//initially all variables are zero

int upperCase=0;

int lowerCase=0;

int nums=0;

int specialCount=0;

//initially the password is invalid

String output="Invalid Password";

//if any criteria is violated ,attach the its message with the ouput

if(givenPassword.length() < 8)

{

output=output+" Must contain a minimum of 8 characters.";

}

if(givenPassword.contains(" "))

{

output=output+" Must not contain spaces.";

}

//iterate through every character of givenPassword and increment the respective variables

//use those variables to check further criteria of password

for ( int k = 0; k < givenPassword.length(); k++ ) {

if (Character.isUpperCase(givenPassword.charAt(k)))

{

upperCase++;

}

else if (Character.isLowerCase(givenPassword.charAt(k)))

{

lowerCase++;

}

else if (Character.isDigit(givenPassword.charAt(k)))

{

nums++;

}

else

{

specialCount++;

}

}

if(upperCase < 1)

{

output=output+" Must contain at least one upper case letter.";

}

if(lowerCase < 1)

{

output=output+" Must contain at least one lower case letter.";

}

if(nums < 1 && specialCount < 1)

{

output = output + " Must contain at least one number or special character.";

}

if(output.equals("Invalid Password"))

{

//password is valid since it when through all the conditions but still remained in its intial state

output = " Valid Password";

}

return output;

}

}

can you add javadocs to this?

(will only accept text uploaded no pictures of handwritten code)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago