Added login capabilities and corrections to previous Python registries

Keywords: Python Pycharm

Think: A previously made registration system can store user registered names and passwords in a dictionary. Simply use if else statements to compare user names entered during user login with previously stored user names when user login. Passwords are the same.

Practice:

1. First I want to compare the values, but I find that the keys in the dictionary cannot be invoked separately (I won't), so I choose to create a new empty dictionary where both user names and passwords are entered as values for invocation.

usernameandkey={}
usernameandkey['usernamed']=f'{username}'
usernameandkey['userkey']=f'{key}'

2. Create a while loop to continue typing when an error occurs and use input () to get the username (password) that the user enters. Then use if else to compare the username and password with the data entered during previous registration. Then I write an if else to compare the accounts, and use input () after the account comparison is successful.To enter the password and then use an if el se to compare the passwords, they are compared to break exit after success, otherwise continue the cycle.

while True:
    enterusername=input("username:")
    if usernameandkey['usernamed']==enterusername:
        enterkey=input("key:")
        if enterkey==usernameandkey['userkey']:
            print("Login Successful")
            break
        else:
            print("Password error")
    else:
        print("Account name does not exist")

Register Login Overall Practice Results:

#Registration System
user_0={}
while True:
    username=input("username:")
    key=input("key:")
    surekey=input("surekey:")
    if key==surekey:
        user_0[f'{username}']=f'{key}'
        #print(user_0) to check if the entry was successful
        break

    else:
        print("\n the key and the surekey not same")

#Logon System
usernameandkey={}
usernameandkey['usernamed']=f'{username}'
usernameandkey['userkey']=f'{key}'
#print(usernameandkey) works as above
while True:
    enterusername=input("username:")
    if usernameandkey['usernamed']==enterusername:
        enterkey=input("key:")
        if enterkey==usernameandkey['userkey']:
            print("Login Successful")
            break
        else:
            print("Password error")
    else:
        print("Account name does not exist")

Reflections: After reading the works of other classmates, I found the shortcomings of my work:

1.That is, when there are multiple user names, my code is cumbersome to store and cannot be compared effectively

2. Empty username or password is not considered

3. Duplicate user names are not taken into account

4. Page language clutter does not take into account user experience issues

Think before modifying:

1. Create a names list to store the user names of all registrants

2. Fill in len() if else to verify that the username and password entered by the user are empty

3. Implement with name in names

4. Unify all page languages into Chinese

Modify practice results:

#Registration System
user_0={}
names=[""]
while True:
    username=input("User name:")
    if username in names:
        print("User name already exists Please re-enter")
    elif len(username)==0:
        print("User name cannot be empty Please re-enter")
    else:
        key=input("Password:")
        if len(key)==0:
            print("Password cannot be empty Please re-enter")
        else:
            surekey = input("Confirm your password again:")
            if key==surekey:
                names.append(username)
                user_0[f'{username}']=f'{key}'
                 #print(user_0)
                break
            else:
                print("\n Passwords entered twice are different Please re-enter")

#Logon System

while True:
    enterusername=input("User name:")
    if enterusername in names:
        enterkey=input("Password:")
        if enterkey==key:
            print("Login Successful")
            break
        else:
            print("Password error")
    else:
        print("Account name does not exist")

Posted by MikeSnead on Thu, 30 Sep 2021 11:24:35 -0700