Jul-23-2020, 09:01 AM
I want to write a program that reads the passwords from a file and compares them with a user input. The comparisons don't seem to work, though. The if-conditions are also called unequal ("ungleich") if this is not the case.
Zu testendes Passwort: password
password ungleich 123456
password ungleich password
password ungleich 12345678
password ungleich qwerty
password ungleich 123456789
Sicher
gefragt = input("Zu testendes Passwort: ") sicher = 1 textdatei = open("passwoerter.txt","r") passwoerter = textdatei.readlines() for test in passwoerter: if test == gefragt: sicher = 0 print (f"{gefragt} gleich {test}") else: print (f"{gefragt} ungleich {test}") if sicher == 0: print("Unsicher") else: print ("Sicher")Output (input=password):
Zu testendes Passwort: password
password ungleich 123456
password ungleich password
password ungleich 12345678
password ungleich qwerty
password ungleich 123456789
Sicher