Python exercise (1): Login

Source: Internet
Author: User

#!/uer/bin/env python#_*_ coding:utf-8 _*_ImportSysretry_limit= 3Retry_count=0account_file='Accounts.txt'Lock_file='Account_lock.txt' whileRetry_count < retry_limit:#loop body limit 3 times executionusername= Raw_input ('\033[32; Username: \033[0m')#Enter user nameLock_check = open (Lock_file)#Open locked File     forLineinchlock_check.readlines (): line= Line.split ()#the loop lock file is compared to the user name entered        ifUesrname = = Line[0]:#Determine user name of user input and lock file first element = =Sys.exit ('\031[31; User%s is locked!\033[0m'%username) Password= Raw_input ('\033[32; Password: \033[0m')#Enter passf = File (Account_file,'r+') Match_flag=False forLineinchF.readlines ():#cyclic ACC file,User,password = Lin.strip ('\ n'). Split ()#split the accounts file to filter line breaks, assign to user, and PSS to list        ifUsername = = User andPassword = = Password:#judgment: The input use equals the user in ACC and PSS equals the input pss in the list            Print('match!'), username Match_flag=True Breakf.close ()ifMatch_flag = = False:#The interpretation flag bit, which does not match by default.         #determine whether user input and pass matches the file, do not deserve to continue the loop, match on the exit.         Print 'User unmatched!'Retry_count+=1Else :        Print('welcom to in Feifei blog system!')Else:    Print("You are locked!") F=file (Lock_file,'AB') F.write (username) f.close ()

Write the Login interface 1. Enter the username and password 2. After successful authentication, welcome information is displayed 3. The error three times after the lock

Python exercise (1): Login

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.