第一天 简单的python认证登陆代码

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# name:zzyu
welcome = '''
-----------welcome to home------------
请选择是否为新用户,请在下面提示中输入<y or n>'''
print (welcome)
new_user = str(input("请输入<y or n>:"))
if new_user == "y":
print ("欢迎注册")
username = str(input("请输入用户名:"))
userpass = str(input("请设置密码:"))
with open('user_pass.txt','a') as file:
file.write("{_username} {_userpass} \n".format(_username=username,_userpass=userpass))
print("欢迎您:{_user_name}".format(_user_name=username))
elif new_user == "n":
dl = str(input("您是否选择登陆,请输入<y or n>:"))
if dl == "y":
username = str(input("请输入用户名:"))
userpass = str(input("请设置密码:"))
with open('user_pass.txt','r') as file1:
# for check in file1.readlines():
check = file1.read()
if username in check and userpass in check:
print ("您好,欢迎回家!!!")
else:
count = 0
while count < 2:
print ("您输入的用户名或密码有误,请重新输入....")
username = str(input("请输入用户名:"))
userpass = str(input("请设置密码:"))
count += 1
if count == 2:
print("您的账号已被锁定......")
else:
print ("BYE BYE")
posted @ 2020-04-12 20:01  zzyu  阅读(262)  评论(0)    收藏  举报