Umstellung des checkSonderzeichen

main
Andreas Wurst 2025-06-02 13:53:42 +02:00
parent 21eab99bc5
commit fce33b6ba4
2 changed files with 18 additions and 5 deletions

View File

@ -3,22 +3,31 @@ import java.util.Scanner;
public class Passwort_Check { public class Passwort_Check {
public static boolean checkLaenge(String passwort) { public static boolean checkLaenge(String passwort) {
if (passwort == null){
return false;
}
// Abfrage mind. Anzahl // Abfrage mind. Anzahl
return passwort.length() >= 20; return passwort.length() >= 20;
} }
public static boolean checkKleinBuchstaben(String passwort) { public static boolean checkKleinBuchstaben(String passwort) {
// Abfrage der Kleinbuchstaben if (passwort == null){
return false;
}// Abfrage der Kleinbuchstaben
return passwort.matches(".*[a-z].*[a-z].*[a-z].*"); return passwort.matches(".*[a-z].*[a-z].*[a-z].*");
} }
public static boolean checkGrossBuchstaben(String passwort) { public static boolean checkGrossBuchstaben(String passwort) {
// Abfrage der Grossbuchstaben if (passwort == null){
return false;
}// Abfrage der Grossbuchstaben
return passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*"); return passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*");
} }
public static boolean checkZiffer(String passwort) { public static boolean checkZiffer(String passwort) {
// Abfrage der Ziffern if (passwort == null){
return false;
}// Abfrage der Ziffern
return passwort.matches(".*[0-9].*[0-9].*[0-9].*"); return passwort.matches(".*[0-9].*[0-9].*[0-9].*");
} }
@ -31,8 +40,11 @@ public class Passwort_Check {
// [^/r] schließt Carriage Return aus // [^/r] schließt Carriage Return aus
// [^/n] schließt Line Feed aus // [^/n] schließt Line Feed aus
// [^A-Za-z0-9\\x00-\\x1F\\x7F] [^A-Za-z0-9\t\r\n] // [^A-Za-z0-9\\x00-\\x1F\\x7F] [^A-Za-z0-9\t\r\n]
String reg = "[\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E]";
return passwort.matches(".*[^A-Za-z0-9\\x00-\\x1F\\x7F].*[^A-Za-z0-9\\x00-\\x1F\\x7F].*[^A-Za-z0-9\\x00-\\x1F\\x7F].*"); return passwort.matches(".*"+reg+".*"+reg+".*"+reg+".*");
//String negReg = "[^A-Za-z0-9\\x00-\\x1F\\x7F]";
//return passwort.matches(".*"+negReg+".*"+negReg+".*"+negReg+".*");
//return passwort.matches(".*[^A-Za-z0-9\\x00-\\x1F\\x7F].*[^A-Za-z0-9\\x00-\\x1F\\x7F].*[^A-Za-z0-9\\x00-\\x1F\\x7F].*");
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -1,3 +1,4 @@
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
// import static org.junit.Assert.assertNull; // import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;