Untitled
unknown
plain_text
4 years ago
3.1 kB
13
Indexable
package cy200;
import java.util.Scanner;
public class Project {
static String dictionary[] = {"Riyadh", "KSA"};
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Email: ");
String email = input.next();
System.out.print("Enter Password: ");
String pass = input.next();
System.out.println(isValid(pass));
}//end main
public static boolean isValid(String pass) {
int capital = 0;
int small = 0;
int number = 0;
int symbol = 0;
//1- Password length should be from 6 to 10 characters.
if (pass.length() >= 6 && pass.length() <= 10) {
//2- Reject any password that is Dictionary words.
for (int i = 0; i < dictionary.length; i++) {
if (pass.toLowerCase().contentEquals(dictionary[i].toLowerCase())) {
System.out.println("Password that is Dictionary words.");
return false;
}//end if
}//end for
//3- Reject any password that has Repetitive characters or numbers.
//4- Reject any password that has Sequential characters or numbers.
//5- Reject any password does not have at least one capital-case letter,
//one small-case letter, one number and one symbol.
for (int i = 0; i < pass.length(); i++) {
char c = pass.charAt(i);
if (Character.isLetter(c)) {
if (Character.isLowerCase(c)) {
small++;
} else {
capital++;
}//end if
}//end if
if (Character.isDigit(c)) {
number++;
}//end if
if (c >= 33 && c <= 47 || c >= 58 && c <= 64) {
symbol++;
}//end if
}//end for
if (small == 0) {
System.out.println("Password does not have at least one small-case letter.");
return false;
}
if (capital == 0) {
System.out.println("Password does not have at least one capital-case letter.");
return false;
}
if (number == 0) {
System.out.println("Password does not have at least one number.");
return false;
}
if (symbol == 0) {
System.out.println("Password does not have at least one symbol.");
return false;
}
//6- Reject any password that similar to email structure.
} else {
System.out.println("Password length should be from 6 to 10 characters.");
return false;
}//end if
return true;
}//end method
public static String randomPassword() {
//If the program can suggest random passwords that satisfy the above conditions you should earn extra 2 marks.
return "";
}
}//end class
Editor is loading...