Writing a login interface method using Python

Source: Internet
Author: User
Python Writing Login interface

First, the demand

To write the login interface:

1. Enter the user name and password to log in

2. Incorrect three-time lock account

3. Next login or Last account, prompt lock, direct exit (use to read and write files)

4. Success after successful display of login

Second, the demand flow chart

Third, code example

Example 1: #!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6 "" Write the Login interface: 1. Enter username and password login 2. Error three lock account 3. Next login or last time Account, prompt lock, direct exit (use to file read/write) 4. Successful display of login success "#lock定义为锁定文件lock =" E:/python_learn/day1/lock "#account定义为账户文件account =" e:/ Python_learn/day1/account "#计数器count = 0# identifier flag = # definition Lock user list is empty lock_user = [] #打开锁定文件 and read locked Account f1 = open (lock, ' r ') lock_ File = F1.readlines () f1.close () #循环锁定账户, append the account to the Lock_user list for i in lock_file:i = I.strip (' \ n ') lock_user.append (i) # Open the account file and read the user and password F2 = open (accounts, ' r ') Account_file = F2.readlines () f2.close () While true:name = input ("Input your name: ") passwd = input (" Input your Password: ") #如果输入的账户在锁定用户列表中, exits the loop; if name in Lock_user:print (" User is lock        !") Break Else: #否则计数器加count +1 count + = 1 #如果count大于2, which is the wrong three times if Count > 2:print         ("Error three times") #将账户添加到锁定账户中 with open (lock, ' a ') as F:f.write ("\ n" + name) break       #如果count小于2, else: #循环输入的用户名和密码, is it the same as the inside of the account file for I in ACCOUNT_FILE:N1,P1 = I.strip (). Split ()                    If name = = N1 and passwd = = P1:print ("Welcome login!!")                    #如果账户密码一样, Flag ID is true flag = True #如果输入账户密码和文件存储的不一样, then jump out of this loop else:  #跳出本次循环 continue #如果flag标识为True, exit the entire loop if flag is true:break Example 2: #!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6 lock = "E:/python_learn/day1/lock" account = "E:/Python_ Learn/day1/account "Count = 0flag = 1lock_user = [] f1 = open (lock, ' r ') Lock_file = F1.readlines () f1.close () for I in Lock_f     ile:i = I.strip (' \ n ') lock_user.append (i) F2 = open (account, ' r ') Account_file = F2.readlines () f2.close () while True:  Name = input ("Input your Name:") passwd = input ("Input your password:") if name in Lock_user:print ("User        Is lock! ") Break Else:cOunt + = 1 for i in account_file:n1, p1 = I.strip (). Split () if name = = N1 and passwd = = P1:                Print ("Welcome login!!")            Flag = True else:continue If flag is True:break else:if count > 2: Print ("Error three times") with open (lock, ' a ') as F:f.write ("\ n" + name) break

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.