PR1/Leon/Uebungsaufgaben/PasswortChecker.java

66 lines
1.9 KiB
Java

package pr2.junit;
import java.util.Scanner;
public class PasswortChecker {
Scanner sc = new Scanner(System.in);
public static int checkPassword(String password) {
int points = 0;
boolean checkNum = false;
boolean checkSo = false;
boolean checkBig = false;
boolean checkLen = false;
//länge >8 +1 // länge -8 -1
if (checkLen == false && password.length() > 7) {
points++;
}
/* else {
points--;
}*/
for (int i = 0; i < password.length(); i ++) {
//Großbuchstaben enhalten +1 /nicht -1
if (checkBig == false && password.charAt(i) > 64 && password.charAt(i) < 90) {
points ++;
checkBig = true;
}
//Sonderzeichen enhalten +1 nicht -1
if (checkSo == false && (password.charAt(i) > 32 && password.charAt(i) < 47 ||
password.charAt(i) > 57 && password.charAt(i) < 65 ||
password.charAt(i) > 90 && password.charAt(i) < 97 ||
password.charAt(i) > 122 && password.charAt(i) < 126 )) {
points ++;
checkSo = true;
}
//Zahl enhalten +1 / nicht -1
if (checkNum == false && password.charAt(i) > 47 && password.charAt(i) < 60) {
points ++;
checkNum = true;
}
}
return points;
}
public static void main(String[] args) {
System.out.println(checkPassword("mutti"));
System.out.println(checkPassword("Mutti"));
System.out.println(checkPassword("mutti123"));
System.out.println(checkPassword("Mutti123"));
System.out.println(checkPassword("Mutti123!%"));
System.out.println(checkPassword("1234"));
}
}