Home > Article > Backend Development > How to write a login interface using python
This article uses python to write a login interface method
Requirements:
Writing a login interface
Enter the user name and password
After successful authentication Display the welcome message
Lock after three inputs
User information file
Blacklist file
Check in the blacklist and do not allow login
Username and password determination
Flow chart:
Code:
#!/usr/bin/env python tries = 0 lockfile = open('account_lock.txt','r+',encoding='UTF-8') tolockfile = open('account_lock.txt','a',encoding='UTF-8') userfile = open('account.txt','r',encoding='utf-8') def islock(account): for line in lockfile: line = line.strip('\n') if line == account: print('此账号已锁定') exit() def inaccount(account): for line in userfile: col1_user,col2_pass = line.strip().split() if col1_user == account: passtries = 0 while passtries < 3: pass1 = input('请输入密码:') if col2_pass == pass1: print('欢迎使用') exit() else: passtries +=1 else: tolockfile.write('%s\n' %(account)) print('账号已锁定!') exit() else: print('此账号不存在') break while tries<3: account = input('请输入账号:') islock(account) inaccount(account) tries +=1 else: print('此用户真的不存在 88') exit() lockfile.close() userfile.close() tolockfile.close() # with open('account_lock.txt','a',encoding='UTF-8') as data: # data.write("aaa") #此方法可以方式忘记文件close #tolockfile = open('account_lock.txt','a',encoding='UTF-8') #open文件后进行追加至最后一行
The above is the detailed content of How to write a login interface using python. For more information, please follow other related articles on the PHP Chinese website!