Language JAVA Create a New Project called YourLastNameValidP
Language: JAVA
Create a New Project called YourLastNameValidPassword.
Write a program that takes two words as input from the keyboard, representing a password and the same password again. (Often, websites ask users to type their password twice when they register to make sure there was no typo the first time around.) Your program should do the following:
If both passwords match, then output \"You are now registered as a new user.\".
Otherwise, output \"Sorry, there is a typo in your password.\".
Input Validation: All valid passwords must contain between 6 and 10 characters, inclusive. Passwords should not be fully numerical (i.e. must contain a mix of letters, numbers, and special characters).
Solution
YourLastNameValidPassword.java
import java.util.Scanner;
public class YourLastNameValidPassword {
public static void main(String[] args) {
String password1,password2;
//Scanner object is used to get the inouits entered by the user
Scanner sc=new Scanner(System.in);
//This loop continues to execute until the user enters valid length of the password
while(true)
{
//Getting the password entered by the user
System.out.print(\"Type Password :\");
password1=sc.next();
//Checking whether the password length is within range or not
if(password1.length()<6 || password1.length()>10)
{
//Displaying the error message
System.out.println(\"** Invalid .Password must be between 6 and 10 **\");
continue;
}
else
break;
}
//This loop continues to execute until the user enters valid length of the password
while(true)
{
//Getting the password entered by the user
System.out.print(\"Re-Type Password :\");
password2=sc.next();
//Checking whether the password length is within range or not
if(password2.length()<6 || password1.length()>10)
{
//Displaying the error message
System.out.println(\"** Invalid .Password must be between 6 and 10 **\");
continue;
}
else
break;
}
//Checking whether the passwords are same or not
if(password1.equals(password2))
{
System.out.println(\"You are now registered as a new user.\");
}
else
{
System.out.println(\"Sorry, there is a typo in your password.\");
}
}
}
___________________________
Output:
Type Password :Williams123$
** Invalid .Password must be between 6 and 10 **
Type Password :Will123$
Re-Type Password :Will123$
You are now registered as a new user.
_____________Thank You

