creating a username and pword program using a #def statement and #dictionary - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: creating a username and pword program using a #def statement and #dictionary (/thread-13410.html) |
creating a username and pword program using a #def statement and #dictionary - zcode12 - Oct-13-2018 I have been trying to get caught up in my college coding class since I had to miss a couple lectures for my grandfathers funeral. We are trying to create a username and password program that has the criteria: must be letters and numbers, and must be greater than 6 characters. I have put over 15+ hours in on this code and feel like I am just getting nowhere. I always run into some type of snag. If anyone is out there that can help me it would mean a lot to a guy trying to get caught up. Here is a sample of my code. userid = {'george7': 'Myid79', 'maryb2':'Watch809'} user = input('Please enter User ID') pwd = '' pword = '' def validate(user): user = user if user.isalpha: return errormsg == 'Must contain letters and numbers' if len(user) < 6: return errormsg == 'Must be at least 6 characters' else: return errormsg == 'ok' def validate(pwd): if pwd.isalpha: return errormsg == 'Must contain letters and numbers' if len(pwd) < 6: return errormsg == 'Must be at least 6 characters' else: return errormsg == 'ok' def validate(pword): if pword.isalpha: return errormsg == 'Must contain letters and numbers' if len(pword) < 6: return errormsg == 'Must be at least 6 characters' else: return errormsg == 'ok' if user in userid: while True: pwd = input('please enter password') if pwd in userid.values(): print('ACCESS GRANTED') break elif pwd not in userid.values(): print('Access Denied please enter valid password') if user not in userid: while True: print('User name not found. \n If user ID criteria met program will ask \n for password and update database') validate(user) if errormsg == 'Must contain letters and numbers': print(errormsg) break elif errormsg == 'Must be at least 6 characters': print(errormsg) break elif errormsg == 'ok': print('Please enter a valid password (same criteria as userid)') pword = input validate(pword) if errormsg == 'Must contain letters and numbers': print(errormsg) break elif errormsg == 'Must be at least 6 characters': print(errormsg) break elif errormsg == 'ok': userid[user] = pwd print('Database has been updated!') break break breakThanks again if anybody even ever sees this and helps. RE: creating a username and pword program using a #def statement and #dictionary - Larz60+ - Oct-13-2018 Please give full assignment, verbatim. RE: creating a username and pword program using a #def statement and #dictionary - woooee - Oct-13-2018 Tutorial on functions http://www.tutorialspoint.com/python/python_functions.htm See "The return Statement". Also there are syntax errors that you should fix and you have 3 functions that all have the same name. RE: creating a username and pword program using a #def statement and #dictionary - volcano63 - Oct-14-2018 (Oct-13-2018, 07:41 PM)zcode12 Wrote:..... if user.isalpha: break In this code, you are not checking the result of isalpha method - because you don't call it. Essentially, you are checking that user.isalpha is non-empty value (it is), so this condition is always true. Add brackets (you do it in all of your functions - somebody has already pointed out that they are called the same).
|