![]() |
Password and Username Verification - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Password and Username Verification (/thread-5958.html) |
Password and Username Verification - AlwaysNew - Oct-30-2017 Hello, I have been doing my coursework for computer science and my teacher advised that we go home and practice python in between hours in the coursework, I need help on Password and Username Verification as it requires the password and username to be stored in a .txt file outside of the program. I do not know how to check the .txt file against the logon information. This also must be able to work with more than one username and password. Thanks I don't know if this violates the homework terms, if so please let me know. Name = input("What is your first Name?\n") while True: try: Age = int(input("What is your age?\n")) Year = int(input("What is your year group?\n")) break except ValueError: print ("Error, Try again") NameFirst = Name[0] NameMain = Name[1:3] Name = NameFirst.upper()+NameMain.lower() #print (Name) Username = (Name + str(Age)) #print (Username) print ("This is your username for the quiz",Username) while True: Password = input("Please Enter a Password\n") PasswordCheck = input("Please Re Enter the password\n") if Password.lower() == PasswordCheck.lower(): break else: print ("Passwords Do Not Match!\nPlease Re Try.") f = open( 'Users.TXT', 'a' ) f.write(Username + '\n' + Password + '\n') f.close() #Logon file = open('Users.TXT', 'r') Data = file.read() file.close() #print (Data) while true LogonUsername = input("Please Enter Your Username\n") RE: Password and Username Verification - heiner55 - Oct-31-2017 >>> I do not know how to check the .txt file against the logon information. users.txt: dan alwaysnew sting beat #Logon user = "alwaysnew" found = False with open('Users.TXT') as file: for line in file: line = line.strip() if user == line: print("user found") found = True break if not found: print("user not found") RE: Password and Username Verification - AlwaysNew - Nov-11-2017 That's a good start, points me in the right direction. Thanks I have made this with the code you made but the first entry in the txt files its the only thing it reads. any answers? def yes(): user = input('Please enter your username\n') found = False with open('Users.TXT') as file: for line in file: line = line.strip() if user == line: print("User Found") found = True passcheck = input('Please enter you password\n') pfound = False with open('Passwords.TXT') as pfile: for line in pfile: line = line.strip() if passcheck == line: print("Password Found") pfound = True menu() break if not pfound: print ('Password not found') yes() if not found: print("user not found") yes() def no(): Name = input("What is your first Name?\n") while True: try: Age = int(input("What is your age?\n")) Year = int(input("What is your year group?\n")) break except ValueError: print ("Error, Try again") NameFirst = Name[0] NameMain = Name[1:3] Name = NameFirst.upper()+NameMain.lower() #print (Name) Username = (Name + str(Age)) #print (Username) print ("This is your username for the quiz",Username) while True: Password = input("Please Enter a Password\n") PasswordCheck = input("Please Re Enter the password\n") if Password.lower() == PasswordCheck.lower(): break else: print ("Passwords Do Not Match!\nPlease Re Try.") f = open( 'Users.TXT', 'a' ) f.write(Username + '\n') f.close() f = open( 'Passwords.TXT', 'a' ) f.write(Password + '\n') f.close() yes() def menu(): File = open ('Menu.TXT', 'r') Menu = File.read() print(Menu) global MenuChoice MenuChoice = input('Please choice 1-4\n') #menu() ##print(MenuChoice) #Main Functions #Password and username generator checkuser = input("Do you have a username?\nY for Yes\nN for No\n") if checkuser.upper() == 'Y': yes() if checkuser.upper() == 'N': no() RE: Password and Username Verification - heiner55 - Nov-12-2017 An extra password file does not make sense. You have to put the password in the user.txt file: dan:password alwaysnew:secret sting:password beat:password3 #Logon user = "alwaysnew" passwd = "secret" found = False with open('Users.TXT') as file: for line in file: uu, pp = line.strip().split(':') if user == uu and passwd == pp: print("user found") found = True break if not found: print("user not found") RE: Password and Username Verification - wavic - Nov-12-2017 You can store the login information in username,password form ( comma separated values ). Not in a plain text of course. Password must be hashed, the username if you want. So, get the name and the password then open the file, check for the name match in each row and compare the hashes. |