53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import random
|
|
|
|
def passwort_zahlen(laenge):
|
|
p = ""
|
|
for _ in range(laenge):
|
|
zufallszahl = random.randint(0, 9)
|
|
p = str(p) + str(zufallszahl)
|
|
return p
|
|
|
|
def passwort_buchstaben(laenge):
|
|
p = ""
|
|
for _ in range(laenge):
|
|
buchstabe = random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
p = str(p) + str(buchstabe)
|
|
return p
|
|
|
|
def passwort_kombi(laenge):
|
|
p = ""
|
|
for _ in range(laenge):
|
|
wahl = random.choice(["zahl", "buchstabe"])
|
|
if wahl == "zahl":
|
|
zufallszahl = random.randint(0, 9)
|
|
p = str(p) + str(zufallszahl)
|
|
else:
|
|
buchstabe = random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
p = str(p) + str(buchstabe)
|
|
return p
|
|
|
|
# Hauptprogramm
|
|
def main():
|
|
print("Passwortgenerator")
|
|
print("1: Nur Zahlen")
|
|
print("2: Nur Buchstaben")
|
|
print("3: Zahlen und Buchstaben")
|
|
|
|
auswahl = input("Deine Wahl (1/2/3): ")
|
|
laenge = int(input("Wie viele Zeichen soll das Passwort haben? "))
|
|
|
|
if auswahl == "1":
|
|
passwort = passwort_zahlen(laenge)
|
|
elif auswahl == "2":
|
|
passwort = passwort_buchstaben(laenge)
|
|
elif auswahl == "3":
|
|
passwort = passwort_kombi(laenge)
|
|
else:
|
|
return
|
|
|
|
print("Passwort:", passwort)
|
|
|
|
# Programm starten
|
|
if __name__ == "__main__":
|
|
main()
|