Python (LoginSystem) Überprüfung ob Nutzername schon existiert
Verfasst: Samstag 17. April 2021, 15:09
Bin gerade dabei ein LoginSystem mit Python zu bauen. Hab ein Problem was Ich selbst durch Googlen nicht beheben konnte in der Funktion Def Register(): muss überprüft werden ob der Nutzername schon existiert, wenn ja gibt er UserName already exist! aus wenn nicht dann Username ok! trotzdem bleibt er in der For Schleife und kommt zu keinem Ende also Endlos.
Code: Alles auswählen
import random
import re
#Guest Number
number = random.randint(1023,9999)#The Random Numbers for Guest####
def Register():
with open('DataList/DataList.txt') as f: #opens the DataList folder and the Txt file it contains
data = f.read() #reads the Txt file
for user in data:
UserName = input("Enter your Username: ")
if UserName in data:#checks if the username is in Data
print("UserName already exist!")# If yes the output will be print
continue
elif not UserName in data:#If the username is not in the txt file
print("Username ok!")#this is output
continue
elif len(UserName) <= 3:#must not be smaller than 3
print("Username is to Short")
continue
elif len(UserName) >= 18:#must not be greater than 18
print("Username is to long")
# while not UserName:#If Input empty output this
# UserName = input("Please input your Username: ")
#Program query
while True:
UserInput = input("Hello Guest#{numbers} Do you have a Account y/n: ".format(numbers=number))#Query whether an account exists or not
if UserInput == "n":#If not give `n` a
Register()
# elif UserInput == "y":#If yes then enter `y`
# Login()
else:
print("None Valid form!")#If the input does not apply at all or is given