My Python growth path---first day---python Basics (Job 1: Login verification)---December 26, 2015 (haze)

Source: Internet
Author: User

1 #!/usr/bin/env Python32 #Coding:utf-83 " "4 Created on:2015 December 295 6 @author: Rockets7 8 Email: [Email protected]9 Ten version:1.0 One  A Description: Enter the user name password, authentication successful display welcome information, authentication failure, the wrong three times after the lock -  - Help : the " " - ImportOS - #Define user Information write function to write user information back to file - defwrite_to_account_file (Accounts, Account_file_path): +Account_file = open (Account_file_path,'W') -      forKey,valinchAccounts.items (): +line = [] A line.append (Key) at Line.extend (val) -         Print(' '. Join (line)) -Account_file.write (' '. Join (line) +'\ n') - account_file.close () -  - if __name__=='__main__': in  -     " " to @parameters: + Account_file_path: Account file - Password_col_num: The column in the account file where the password is located (starting from 0) the Status_col_num: The column where the account status is located in the account file (starting from 0) * Error_count_num: The column where the number of errors was entered in the account file (starting from 0) $ App_info: System Information for starting the output after applicationPanax Notoginseng welcome_msg: Information After the user successfully logs on to the system -     " " theAccount_file_path ='account.db' +Password_col_num = 1 AStatus_col_num = 2 theError_count_num = 3 +App_info =" " - +-----------------------------------+ $ | Welcome to 65brother system | $ | version:1.0 | - | Author:zhangxiaoyu | - +-----------------------------------+ the " " -Welcome_msg ='Welcome%s, authentication is successful!'Wuyi     #determine if the account file exists the     ifos.path.exists (account_file_path): -Account_file = open (Account_file_path,'R') Wu     Else: -         Print('error:account file "Account.db" isn't exit, please check!') AboutExit (1) $  -     #Read Account file -accounts = {} -      forLineinchaccount_file.readlines (): AAccount =Line.strip (). Split () +Accounts[account[0]] = account[1:] the account_file.close () -  $Flag =True the      whileflag: the         Print(App_info) the         #Enter user name theUsername = input ('Username (Enter quit to exit):'). Strip () -         #determine if the input is a quit in         ifUsername = ='quit': the             #Yes then exit the loop and the program ends the              Break AboutPassword = input ('Password:'). Strip () the         #determine if the user name exists the         ifUsername not inchAccounts: the             #There is no prompt error message and exits the current loop so that the user re-enters +             Print('Error:username or Password it is error!') -             Continue the         #determine if the user is locked outBayi         ifACCOUNTS[USERNAME][STATUS_COL_NUM-1] = ='Lock': the             #If you are locked out of the current loop let's use re-entry the             Print('Error:account is locked. please contact the administrator!') -             Continue -         #determine if the user's password is correct the         ifPassword = = Accounts[username][password_col_num-1]: the             #display welcome information correctly the             Print(Welcome_msg%username) the              Break -         Else: the             #not correct the             #Prompt for user name or password error the             Print('Error:username or Password it is error!')94             #number of input errors plus 1 theACCOUNTS[USERNAME][ERROR_COUNT_NUM-1] = str (int (accounts[username][error_count_num-1)) + 1) the             #Judging whether it has reached 3 times the             ifInt (accounts[username][error_count_num-1]) = = 3:98                 #if the input error reaches 3 times About                 #prompt account will be locked -                 Print("error:this account is locked, please contact the administrator! System would be exit!")101                 #change user state to lock and write to file102ACCOUNTS[USERNAME][STATUS_COL_NUM-1] ='Lock'103 write_to_account_file (Accounts, Account_file_path)104                  Break theWrite_to_account_file (Accounts, Account_file_path)

My Python growth path---first day---python Basics (Job 1: Login verification)---December 26, 2015 (haze)

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.