编写登录接口

# -*- coding:utf-8 -*-
# Author:WuGui Xiao
import getpass,sys,re

_username = "xiaowugui"
_password = "Test123"

def user_login(_username,_password):

for i in range(3):
'''
getpass.getpass() -- 显示提示字符串,关闭键盘屏幕回显,然后读取密码 --- 加密(在交互式命令行中使用)
'''
username = input("please enter username:")
password = getpass.getpass("Please enter password:")

# 写入
with open(r"../student.txt",'a+',encoding="utf-8") as addUser:
addUser.write(username+"\n")

if username == _username and password == _password:
print(f"Welcome user {username} login success!!")
sys.exit()
else:
# 读取用户名后,再统计username出现的次数
with open(r"../student.txt", 'r', encoding="utf-8") as readUser:
words = readUser.read()
total = len(re.findall(username, words))
if total >= 3:
print("User has been locked for 30 seconds..!")
else:
print("wrong user name or password.")

user_login(_username,_password)

 

posted @ 2021-02-06 16:57  小蜗牛,背干锅  阅读(81)  评论(0编辑  收藏  举报