Python-based login interface and python-based interface

Source: Internet
Author: User

Python-based login interface and python-based interface

1. Enter the user name and password;

2. After successful authentication, the welcome information is displayed;

3. After three errors, the account is locked.

 

Account file: user.txt

Lock file: locked.txt

The flowchart is as follows:

#-*-Coding: UTF-8-*-# Author Caoxlimport sysaccount_file = 'e: \ user.txt 'locked _ file = 'e: \ locked.txt 'def deny_account (username ): print ('your user has been locked ') with file (locked_file, 'A') as deny_f: deny_f.write (' \ n' + username) def main (): retry_count = 0 retry_limit = 3 # loop times while retry_count <retry_limit: # the user can log on three times at most. username = raw_input ('enter your username :') # instruct the user to enter the user name with file (locked_file, 'R') as lock_f: # Use the with method to open locked_f Ile value lock_f to prevent forgetting f. close () close the file for line in lock_f.readlines (): # cyclically traverse the content of each row if len (line) = 0: # process each line of content. continue if username = line. strip (): # exploitation. strip removes the linefeed to match the username. Sys. exit ('the user is locked! ') If len (username) = 0: # the user name cannot be blank when prompted to log on! Print ('user name cannot be blank; enter 'Again) continue password = raw_input ('enter your password:') # instruct the user to enter the password with file (account_file, 'R') as account_f: flag = False for line in account_f.readlines (): user, pawd = line. strip (). split () # process the user name and password. if username = user and password = pawd: # determine the user name and password print ('success! ') Flag = True break # exit for loop if flag = False: # Do not prompt users to re-enter after three inputs. If retry_count <2: print ('the user name or password you entered is incorrect. Please enter it again! ') Retry_count + = 1 else: print (' Welcome to the successful login !! ') Break # The flag is used to successfully launch the entire cycle! Deny_account (username) # Add the locked account to the document using the def function above. if _ name _ = '_ main _': main ()
View Code

 

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.