day1作业

import os
import csv


# 作业:编写登录接口,认证成功后显示欢迎信息,输错三次后锁定
# 创建两个空列表用来存储账号密码
name = []
word = []
# 读取账号密码文件
with open('username_password.csv','r',encoding='utf-8') as a:
b = csv.reader(a)
for row in b:
name.append(row[0])
word.append(row[1])
#创建账号信息字典
dict_menus = dict(zip(name, word))
#读取被锁定的账号信息
with open('lock_name.csv','r',encoding='utf-8') as lock_name:
lock_list = csv.reader(lock_name)
lock_list_name = [row[0] for row in lock_list]
#获取输入的账号密码
x = 0
while x<3:
username = input('请输入你的账号:')
password = input('请输入你的密码:')
# 判断账号是否被锁定
if username in lock_list_name:
print('对不起,您的账号已被锁定')
break
else:
# 判断账号密码是否正确
if username in dict_menus.keys() and dict_menus[username] == password:
print('恭喜你,登录成功')
break
else:
print('对不起,你输入的账号或密码错误!请重新输入')
x+=1
else:
with open('lock_name.csv','a',encoding='utf-8') as write_name:
write_name.write(username+'\n')
print('对不起,您已经输错三次,账号已被锁定')

你可能感兴趣的:(day1作业)