Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

question please help me

0 votes
asked May 10, 2020 by Moza Muslem Salim Rashid Al Tobi (120 points)

Careers Online is setting up their website. They need a strong code to validate the password given by the user while registering. The developer has designed a few rules for the password. Help him to write the Java program that can validate the input password. 1) The password must exceed 10 characters. [2] 2) The password characters must not contain capital letters or small letters, it may contain a combination of digits and any special characters (#, $, @, &, *). [3] 3) The password must start with a digit but the digit must not be 0. [2] 4) The password must end with the special character but not with @. [2] 5) If any one of the rules is not satisfied, prompt the user to type the password again. [2] 6) If all the rules are satisfied then display a “Password Saved” message.

1 Answer

0 votes
answered May 26, 2020 by INFYPY175 (140 points)
import java.util.Scanner;

public class Password {

public static boolean validPwd(String pwd) {

int validity = 0;

char first = pwd.charAt(0);

char last = pwd.charAt(pwd.length()-1);

if(pwd.length()<10) {

validity = 1;

}

if(validity == 0) {

for(int i=0;i<pwd.length();i++) {

if(Character.isAlphabetic(pwd.charAt(i))) {

validity = 1;

break;

}

}

if(validity == 0) {

boolean firstch = !Character.isDigit(last)&& !Character.isAlphabetic(last);

if(firstch && last != '@') {

validity = 0;

}

else

validity = 1;

}

if(validity == 0) {

boolean digit = first!='0' && Character.isDigit(pwd.charAt(0));

if(digit == true)

validity = 0;

else

validity = 1;

}

}

if(validity !=0 )

return false;

else

return true;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

boolean accept = false;

while(accept == false) {

System.out.println("Enter valid password:");

String pwd = sc.nextLine();

accept = validPwd(pwd);

}

if(accept==true)

System.out.println("Password Saved");

sc.close();

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...