From e66ccc4211308dddf6fafe3432c9ce99b2db8173 Mon Sep 17 00:00:00 2001 From: Carumar <1720808@stud.hs-mannheim.de> Date: Wed, 21 May 2025 18:53:54 +0200 Subject: [PATCH] erster Versuch --- Passwort_Check.java | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Passwort_Check.java diff --git a/Passwort_Check.java b/Passwort_Check.java new file mode 100644 index 0000000..4bb9fe2 --- /dev/null +++ b/Passwort_Check.java @@ -0,0 +1,76 @@ +import java.util.Scanner; + +public class Passwort_Check { + 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 = ckeckKleinBuchstaben(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(); + } + + 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 ckeckKleinBuchstaben(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; + } + +}