(Python) Writing the login interface

Source: Internet
Author: User

Requirements:

1. Enter the user name, password

2. Display welcome message after successful authentication

3. Input error 3 times after being locked

Flow chart:

The password_file format for creating the password file is as follows:

ADO 123

AAA 234

BBB 456

The lock file format is as follows:

Ado

Aaa

Bbb

The code is as follows:

Count_input = 0#error count, prompt for error 3 timesLock_list = []#Lock list, continuous error 3 prompt and add to user lock file forIinchRange (3): Count_input+ = 1Input_account= Input ("Input your account:") Input_password= Input ("Input your password:") lock_list.append (input_account)#add a user to a locked listF1 = open ("Password_file","R")#Read account password fileF2 = open ("Lock_file","R")#Read user lock file         forLine2inchF2:ifInput_account.strip () = = Line2.strip ():#to determine whether the user output account is equal to the locked file line, which is the user lock state, prompts to exit, or continue                Print("your account has been locked! quit ...") F2.close () Break        Else:             forLine1inchF1:ifinput_account+" "+input_passwordinchLINE1:#determine if the output account password is equal to the account password file, equal to print the welcome message and exit, or continue                    Print("Welcome back!") F1.close () Break            Else:                ifCount_input < 3:#when the error counter is less than 3 o'clock, prompt for re-entry, continue the next loop                    Print("wrong! Please input again!")                    Continue                Else:                    ifLock_list.count (input_account) = = 3:#when the error counter equals 3 o'clock, the user is prompted to be locked out and                        Print("wrong Password!your account has been lock") F2= Open ("Lock_file","a")#Open User lock file in append formF2.write (input_account+"\ n")#to add a locked user to a locked filef2.close ()Else:                        Print("You have input wrong password 3 times,quit.")#three times input account not all the same time, print this line, and exit                     Break         Break

(Python) Writing the login interface

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.