Python Forum

Full Version: creating a username and pword program using a #def statement and #dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
        break
Thanks again if anybody even ever sees this and helps.
Please give full assignment, verbatim.
Tutorial on functions http://www.tutorialspoint.com/python/pyt...ctions.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.
(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).