Python User Login module (methods such as not using functions)

Source: Internet
Author: User

* User Login Module

Given the user Information table, the following conditions need to be met:

1. Enter user name password to judge

2. Enter the number of errors 3 times, ask the user if you need to continue to try, y continue, N end

3. Can support multi-user Login

1 #Scenario One: Once the user name is entered, once, a total of three times2Li = [{'username':'QQQ','Password':'www'},3{'username':'AAA','Password':'SSS'},4{'username':'zzz','Password':'XXX'}]5 6 #convert the original list to a new dictionary for easy comparison7New_users_info = {}8  forIinchLi:9new_users_info[i['username']] = i['Password']Ten  OneCount_try_username, Count_try_password = 0, 0#Number of user name attempts, password attempts AFlag_username, Flag_password, flag_selection = 1, 1, 1#Loop to user name input, loop to password input, loop to continue -  whileFlag_username: -Count_try_username + = 1 theUsername_input = input ('Please enter user name:') -     ifUsername_inputinchNew_users_info.keys ():#determine if the user name exists -Count_try_password = 0#user name attempts are zeroed/or returned to 1 -Flag_password, flag_selection = 1, 1#all loops Start again +          whileFlag_password: -Password_input = input ('Please enter your password:') +             ifPassword_input = = New_users_info[username_input]:#determine if the password matches the user name A                 Print('Login Successful! Jump to App usage page') atFlag_username =0 -                  Break -             Else: -Count_try_password + = 1 -                 Print('Password input error ...%s times'%Count_try_password) -                 ifCount_try_password = = 3: in                      whileflag_selection: -User_selection = input ('do you want to continue? y/n') toUser_selection =User_selection.lower () +                         ifUser_selection = ='y': -Count_try_username, Count_try_password =0, 0 theFlag_password =0 *Flag_selection =0 $                         elifUser_selection = ='N':Panax NotoginsengFlag_username =0 -Flag_password, flag_selection =0, 0 the                             Print('Byebye ...') +                         Else: A                             Print('Error Selection') the     Else: +         Print('user name input error ...%s times'%count_try_username) -         ifCount_try_username = = 3: $Flag_password, flag_selection = 1, 1#all loops Start again $              whileflag_selection: -User_selection = input ('do you want to continue? y/n') -User_selection =User_selection.lower () the                 ifUser_selection = ='y': -Count_try_username =0WuyiFlag_password =0 theFlag_selection =0 -                 elifUser_selection = ='N': WuFlag_username =0 -Flag_password, flag_selection =0, 0 About                     Print('Byebye ...') $                 Else: -                     Print('Error Selection')
determine if the user name is correct

The above code will determine the user name error three times the case.

The following code does not determine the user name error, only to determine the match.

1 #User Login (three chance retry), can support multi-user login, three times can choose y/n decide whether to continue to try2 #Scenario Two: Do not judge the number of user name errors, only to determine whether the password is wrong3Li = [{'username':'Li_alex','Password':'SB'},4{'username':'Wu_sir','Password':'SB'},5{'username':'Xu_jin','Password':'Student'}]6 7New_user_info = {}8  forUser_infoinchLi:9new_user_info[user_info['username']] = user_info['Password']Ten Print(New_user_info) One  A  while1: -Count =0 -Username_entry = input ('Please Input an Username:') the     ifUsername_entryinchNew_user_info.keys (): -Password_entry = input ('Please Input the Password:') -          whileCount < 2 andPassword_entry! =New_user_info[username_entry]: -Count + = 1 +             Print('wrong Password Input,%d time (s) left ...'% (3-count)) -Password_entry = input ('Please Input the Password:') +         Else: A             ifPassword_entry = =New_user_info[username_entry]: at                 Print('congratulations! Login succeed!') -                  Break -             elifCount > 1: -User_selection = input ('Invalid time exceeds Limited, do you wanna Try Again? y/n') -Lower_entry =User_selection.lower () -                 ifLower_entry = ='y': in                     Continue -                 elifLower_entry = ='N': to                     Print('You Give up Login attempt. Good luck ... (Manual smile)') +                      Break -                 Else: the                     Print('wrong Selection ... Please Try Again ...') *                     Continue $             Else:Panax Notoginseng                 Print("Error")
determine user name and password matching

Do not use functions, etc., only with while/for/if-else loops

Python User Login module (methods such as not using functions)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.