Python Forum
creating a username and pword program using a #def statement and #dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a username and pword program using a #def statement and #dictionary
#1
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.
Reply
#2
Please give full assignment, verbatim.
Reply
#3
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.
Reply
#4
(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).
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,758 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Hiding username and password on sql tantony 10 2,955 Oct-21-2022, 07:58 PM
Last Post: wavic
  Pulling username from Tuple pajd 21 3,434 Oct-07-2022, 01:33 PM
Last Post: pajd
  getting an import statement to work in my program barryjo 1 1,671 Dec-06-2021, 04:28 PM
Last Post: snippsat
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,932 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  creating simplex tableau pivot program easy or difficult for a beginner in Python? alex_0 2 2,592 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  Creating a dictionary from a list Inkanus 5 3,173 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  Trying to create a conditional with a username Realen 2 1,835 Jun-20-2020, 12:44 AM
Last Post: Realen
  Creating Discord Bot: Unused import statement 'import discord EyeballCandy 0 3,565 Feb-02-2020, 10:53 PM
Last Post: EyeballCandy
  creating hex dump modifying program ensoniq 3 2,645 Oct-14-2019, 08:21 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020