I need help with the code for a valid password. Below is what the instructor wan
ID: 3631617 • Letter: I
Question
I need help with the code for a valid password. Below is what the instructor wants.. Thanks for the help.
Project: Checking Password
Problem Description:
Some Websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rule is as follows:
Here is the start of the code that she wants us to us
public static boolean isvalid(String password)
{
boolean goodSoFar= True;
int numDigits= 0;
int numLetters = 0;
int numOthers=0;
Write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password" otherwise.
Sample 1
Enter a string for password: wewew43x
valid password
Sample 2
Enter a string for password: 343a
invalid password
Analysis:
(Describe the purpose, processing, input and output in your own words.)
Design:
(Describe the major steps for solving the problem.)
Testing: (Describe how you test this program)
Explanation / Answer
please rate - thanks
import java.util.Scanner;
public class ValidPassword
{
public static void main (String[] args)
{String password;
Scanner input = new Scanner(System.in);
System.out.print("Enter a string for password: ");
password=input.next();
if(isvalid(password))
System.out.println("valid password");
else
System.out.println("invalid password");
}
public static boolean isvalid(String password)
{boolean goodSoFar=true;
int numDigits= 0;
int numLetters = 0;
int numOthers=0;
if(password.length()<8)
goodSoFar= false;
if(goodSoFar)
{for(int i=0;i<password.length();i++)
if(Character.isLetter(password.charAt(i)))
numLetters++;
else if(Character.isDigit(password.charAt(i)))
numDigits++;
else
numOthers++;
}
if(numOthers>0)
goodSoFar=false;
if(numDigits<2||numLetters<2)
goodSoFar=false;
return goodSoFar;
}
}