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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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:
1
2
3
.....
    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
  checking username newbexx 3 1,211 Jun-17-2024, 11:42 AM
Last Post: Pedroski55
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 6,298 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Hiding username and password on sql tantony 10 7,243 Oct-21-2022, 07:58 PM
Last Post: wavic
  Pulling username from Tuple pajd 21 6,997 Oct-07-2022, 01:33 PM
Last Post: pajd
  getting an import statement to work in my program barryjo 1 2,440 Dec-06-2021, 04:28 PM
Last Post: snippsat
  Class-Aggregation and creating a list/dictionary IoannisDem 1 2,770 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 3,563 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  Creating a dictionary from a list Inkanus 5 4,246 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  Trying to create a conditional with a username Realen 2 2,568 Jun-20-2020, 12:44 AM
Last Post: Realen
  Creating Discord Bot: Unused import statement 'import discord EyeballCandy 0 4,454 Feb-02-2020, 10:53 PM
Last Post: EyeballCandy

Forum Jump:

User Panel Messages

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