diff --git a/Passwort_Check.java b/Passwort_Check.java index 25b57ca..ffb7052 100644 --- a/Passwort_Check.java +++ b/Passwort_Check.java @@ -3,7 +3,7 @@ import java.util.Scanner; public class Passwort_Check { public static boolean checkLaenge(String passwort) { - if (passwort == null){ + if (passwort == null) { return false; } // Abfrage mind. Anzahl @@ -11,40 +11,44 @@ public class Passwort_Check { } public static boolean checkKleinBuchstaben(String passwort) { -if (passwort == null){ + if (passwort == null) { return false; - }// Abfrage der Kleinbuchstaben + } // Abfrage der Kleinbuchstaben return passwort.matches(".*[a-z].*[a-z].*[a-z].*"); } public static boolean checkGrossBuchstaben(String passwort) { -if (passwort == null){ + if (passwort == null) { return false; - }// Abfrage der Grossbuchstaben + } // Abfrage der Grossbuchstaben return passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*"); } public static boolean checkZiffer(String passwort) { -if (passwort == null){ + if (passwort == null) { return false; - }// Abfrage der Ziffern + } // Abfrage der ZiffernS return passwort.matches(".*[0-9].*[0-9].*[0-9].*"); } public static boolean checkSonderZeichen(String passwort) { + if (passwort == null) { + return false; + } // Überprüfung mit Regex durch Ausschluss // [^A-Za-z0-9] Schließt alle ziffern und Buchstaben aus - // Ausschlus der Steuerzeichen: + // Ausschlus der Steuerzeichen: // [^/t] schließt Tab aus // [^/r] schließt Carriage Return aus - // [^/n] schließt Line Feed aus - // [^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(".*"+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].*"); + // [^/n] schließt Line Feed aus + // [^A-Za-z0-9\\x00-\\x1F\\x7F] [^A-Za-z0-9\t\r\n] + String reg = "[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E\\x80]"; + 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) { diff --git a/Test_Passwords_Oliver_S.java b/Test_Passwords_Oliver_S.java index 0f1e0aa..735fdbf 100644 --- a/Test_Passwords_Oliver_S.java +++ b/Test_Passwords_Oliver_S.java @@ -1,4 +1,3 @@ -package Pflichtuebung_4; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -45,7 +44,7 @@ public class Test_Passwords_Oliver_S { final static int STOP_CHAR_SONDERZ_3 = 96; final static int START_CHAR_SONDERZ_4 = 123; - final static int STOP_CHAR_SONDERZ_4 = 127; + final static int STOP_CHAR_SONDERZ_4 = 126; @FunctionalInterface interface Check_X_Interface{