Python exercise _ module01-1-simulated login, python_module01-1-

Source: Internet
Author: User

Python exercise _ module01-1-simulated login, python_module01-1-

1. Save account information to the pickle file for calling

1 import pickle2 3 acc = {'abc':'123'}4 5 with open('acc.pkl','wb') as f:6     pickle.dump(acc,f)

2. Main Program

1 #! /Usr/bin/env python3 2 #-*-coding: UTF-8-*-3 # Author: Jailly 4 5 import easygui as g 6 import pickle, OS 7 8 # login function 9 def login (acc_ SQL, locked_acc_ SQL): 10 n = 011 12 while n <14 # Get the user input 15 acc = g. multpasswordbox ('enter your username and password: ', fields = ('username', 'Password') 16 17 # Remove spaces on both sides of the username 18 if acc: 19 acc [0] = acc [0]. strip () 20 21 # click cancel to exit 22 else: 23 exit () 24 25 # account locking 26 if acc and acc [0] in locked_acc_ SQL: 27g. msgbox ('Sorry, your account has been locked! ') 28 exit () 29 30 # enter the correct account and password 31 elif acc and acc [0] in acc_ SQL and acc [1] = acc_ SQL [acc [0]: 32g. msgbox ('login successful! ') 33 exit () 34 35 # case where the user name is not in the account dictionary 36 elif acc and acc [0] not in acc_ SQL: 37 acc = g. msgbox ('the user name you entered does not exist, Please re-enter ') 38 39 # the user name is in the account dictionary, but the password entered incorrectly 40 else: 41 acc = g. msgbox ('user name or Password error, Please re-enter ') 42 n + = 143 44 # Processing 45 with open ('locked _ acc. pkl ', 'wb') as f: 46 locked_acc_ SQL .append (acc [0]) 47 pickle. dump (locked_acc_ SQL, f) 48 49g. msgbox ('Sorry, the password has been entered incorrectly more than 3 times and your account has been locked! ') 50 51 if _ name _ =' _ main _ ': 52 53 # dictionary consisting of account and password in advance {'abc ': '200'} stores the pickle file and imports the dictionary 54 with open ('Acc. pkl ', 'rb') as f: 55 acc_ SQL = pickle. load (f) 56 57 # initialize 'locked account' list 58 if not OS .path.exists('locked_acc.zip '): 59 with open ('locked _ acc. pkl ', 'wb') as f: 60 pickle. dump ([], f) 61 62 # export 'locked account' list 63 with open ('locked _ acc. pkl ', 'rb') as f: 64 locked_acc_ SQL = pickle. load (f) 65 66 login (acc_ SQL, locked_acc_ SQL)

 

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.