Hinzufügen einer JUnit
parent
fa01b64a38
commit
d02917fa00
|
|
@ -2,74 +2,61 @@ import java.util.Scanner;
|
|||
|
||||
public class Passwort_Check {
|
||||
|
||||
public static String checkLaenge(String passwort) {
|
||||
String ausgabe = "Passwort ist zu kurz";
|
||||
if (passwort.length() >= 20) {
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
}
|
||||
return ausgabe;
|
||||
public static boolean checkLaenge(String passwort) {
|
||||
return passwort.length() >= 20;
|
||||
}
|
||||
|
||||
public static String checkKleinBuchstaben(String passwort) {
|
||||
String ausgabe = "Es fehlen Kleinbuchstaben";
|
||||
if (passwort.matches(".*[a-z].*[a-z].*[a-z].*")) {
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
}
|
||||
return ausgabe;
|
||||
public static boolean checkKleinBuchstaben(String passwort) {
|
||||
|
||||
return passwort.matches(".*[a-z].*[a-z].*[a-z].*");
|
||||
}
|
||||
|
||||
public static String checkGrossBuchstaben(String passwort) {
|
||||
String ausgabe = "Es fehlen Großbuchstaben";
|
||||
if (passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
public static boolean checkGrossBuchstaben(String passwort) {
|
||||
|
||||
return passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*");
|
||||
}
|
||||
|
||||
public static String checkZiffer(String passwort) {
|
||||
String ausgabe = "Es fehlen Ziffern";
|
||||
if (passwort.matches(".*[0-9].*[0-9].*[0-9].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
public static boolean checkZiffer(String passwort) {
|
||||
|
||||
return passwort.matches(".*[0-9].*[0-9].*[0-9].*");
|
||||
}
|
||||
|
||||
public static String checkSonderZeichen(String passwort) {
|
||||
String ausgabe = "Es fehlen Sonderzeichen";
|
||||
if (passwort.matches(".*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
public static boolean checkSonderZeichen(String passwort) {
|
||||
|
||||
return passwort.matches(".*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String passwort = null;
|
||||
String checkResultat = "Passwort ist sicher.";
|
||||
|
||||
boolean check = true;
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.println("Geben Sie ein Passwort zur überprüfung ein:");
|
||||
|
||||
passwort = in.nextLine();
|
||||
do {
|
||||
checkResultat = checkLaenge(passwort);
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkKleinBuchstaben(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkGrossBuchstaben(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkZiffer(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkSonderZeichen(passwort);
|
||||
}
|
||||
if (checkResultat != "Passwort ist sicher.") {
|
||||
check = false;
|
||||
System.out.println(checkResultat + "\n Geben Sie ein verbessertes Passwort zur überprüfung ein:");
|
||||
passwort = in.nextLine();
|
||||
|
||||
if (!checkLaenge(passwort)) {
|
||||
System.out.println("Passwort ist zu kurz!");
|
||||
} else if (!checkKleinBuchstaben(passwort)) {
|
||||
System.out.println("Es fehlen Kleinbuchstaben!");
|
||||
} else if (!checkGrossBuchstaben(passwort)) {
|
||||
System.out.println("Es fehlen Großbuchstaben!");
|
||||
} else if (!checkZiffer(passwort)) {
|
||||
System.out.println("Es fehlen Ziffern!");
|
||||
} else if (!checkSonderZeichen(passwort)) {
|
||||
System.out.println("Es fehlen Sonderzeichen!");
|
||||
} else {
|
||||
System.out.println("Passwort ist sicher.");
|
||||
check = true;
|
||||
break; // Optional, da Schleife sonst sowieso endet
|
||||
}
|
||||
if (check == false) {
|
||||
System.out.println("Geben Sie ein verbessertes Passwort zur überprüfung ein:");
|
||||
passwort = in.nextLine();
|
||||
}
|
||||
} while (check == false);
|
||||
System.out.println(checkResultat);
|
||||
|
||||
System.out.println("...und Tschüss");
|
||||
in.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class Passwort_Check1 {
|
||||
|
||||
public static boolean checkLaenge(String passwort) {
|
||||
return passwort.length() >= 20;
|
||||
}
|
||||
|
||||
public static boolean checkKleinBuchstaben(String passwort) {
|
||||
|
||||
return passwort.matches(".*[a-z].*[a-z].*[a-z].*");
|
||||
}
|
||||
|
||||
public static boolean checkGrossBuchstaben(String passwort) {
|
||||
|
||||
return passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*");
|
||||
}
|
||||
|
||||
public static boolean checkZiffer(String passwort) {
|
||||
|
||||
return passwort.matches(".*[0-9].*[0-9].*[0-9].*");
|
||||
}
|
||||
|
||||
public static boolean checkSonderZeichen(String passwort) {
|
||||
|
||||
return passwort.matches(".*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String passwort = null;
|
||||
|
||||
boolean check = true;
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.println("Geben Sie ein Passwort zur überprüfung ein:");
|
||||
|
||||
passwort = in.nextLine();
|
||||
do {
|
||||
|
||||
if (!checkLaenge(passwort)) {
|
||||
System.out.println("Passwort ist zu kurz!");
|
||||
} else if (!checkKleinBuchstaben(passwort)) {
|
||||
System.out.println("Es fehlen Kleinbuchstaben!");
|
||||
} else if (!checkGrossBuchstaben(passwort)) {
|
||||
System.out.println("Es fehlen Großbuchstaben!");
|
||||
} else if (!checkZiffer(passwort)) {
|
||||
System.out.println("Es fehlen Ziffern!");
|
||||
} else if (!checkSonderZeichen(passwort)) {
|
||||
System.out.println("Es fehlen Sonderzeichen!");
|
||||
} else {
|
||||
System.out.println("Passwort ist sicher.");
|
||||
check = true;
|
||||
break; // Optional, da Schleife sonst sowieso endet
|
||||
}
|
||||
if (check == false) {
|
||||
System.out.println("Geben Sie ein verbessertes Passwort zur überprüfung ein:");
|
||||
passwort = in.nextLine();
|
||||
}
|
||||
} while (check == false);
|
||||
|
||||
System.out.println("...und Tschüss");
|
||||
in.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class Passwort_Check_sk {
|
||||
|
||||
public static String checkLaenge(String passwort) {
|
||||
String ausgabe = "Passwort ist zu kurz";
|
||||
if (passwort.length() >= 20) {
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
}
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
public static String checkKleinBuchstaben(String passwort) {
|
||||
String ausgabe = "Es fehlen Kleinbuchstaben";
|
||||
if (passwort.matches(".*[a-z].*[a-z].*[a-z].*")) {
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
}
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
public static String checkGrossBuchstaben(String passwort) {
|
||||
String ausgabe = "Es fehlen Großbuchstaben";
|
||||
if (passwort.matches(".*[A-Z].*[A-Z].*[A-Z].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
public static String checkZiffer(String passwort) {
|
||||
String ausgabe = "Es fehlen Ziffern";
|
||||
if (passwort.matches(".*[0-9].*[0-9].*[0-9].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
public static String checkSonderZeichen(String passwort) {
|
||||
String ausgabe = "Es fehlen Sonderzeichen";
|
||||
if (passwort.matches(".*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*[!\\?\\$%&#@*+\\-=_.].*"))
|
||||
ausgabe = "Passwort ist sicher.";
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String passwort = null;
|
||||
String checkResultat = "Passwort ist sicher.";
|
||||
boolean check = true;
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.println("Geben Sie ein Passwort zur überprüfung ein:");
|
||||
|
||||
passwort = in.nextLine();
|
||||
do {
|
||||
checkResultat = checkLaenge(passwort);
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkKleinBuchstaben(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkGrossBuchstaben(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkZiffer(passwort);
|
||||
}
|
||||
if (checkResultat == "Passwort ist sicher.") {
|
||||
checkResultat = checkSonderZeichen(passwort);
|
||||
}
|
||||
if (checkResultat != "Passwort ist sicher.") {
|
||||
check = false;
|
||||
System.out.println(checkResultat + "\n Geben Sie ein verbessertes Passwort zur überprüfung ein:");
|
||||
passwort = in.nextLine();
|
||||
} else {
|
||||
check = true;
|
||||
}
|
||||
} while (check == false);
|
||||
System.out.println(checkResultat);
|
||||
System.out.println("...und Tschüss");
|
||||
in.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import org.junit.jupiter.api.Test;
|
||||
// import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class Test_Passwort_Check {
|
||||
@Test
|
||||
public void testPasswortZuKurz() {
|
||||
assertFalse(Passwort_Check.checkLaenge("Hello Wolrd"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue