## 1、實現用戶註冊功能# 思路:# 用戶輸入用戶名、密碼# 將用戶輸入的內容按照固定的格式,好比:egon:123,存入文件# 能夠往一個文件中重複註冊新的用戶名和密碼# 附加:# 一、對輸入的用戶名進行合法性監測,不能以數字開頭,且若是輸入的用戶名已存在於文件中則要求用戶從新輸入# 二、對輸入的密碼進行合法性監測,密碼的長度至少6位,而且不能包含特殊字符*&$# y=[]# print('註冊請填寫如下信息')# tag=True# with open(r'db.txt', mode='rt', encoding='utf-8')as x:# for data_name in x:# d_name = data_name.strip('\n').split(':')# y.append(d_name[0])# # print(y)# while tag:# name = input('username>>>').strip()# if name[0].isdigit():# print('不能以數字開頭,請從新輸入')# continue# if name in y:# print('已被註冊,請從新輸入')# continue# while tag:# pwd = input('password>>>').strip()# if len(pwd)<6:# print('密碼的長度至少6位')# continue# if pwd.find('$') != -1:# print('不能包含特殊字符*&$')# continue# else: print('註冊成功')# with open(r'db.txt', mode='at', encoding='utf-8')as f:# data = '%s:%s\n' % (name, pwd)# f.write(data)# tag = False# 2、實現用戶驗證功能更:# 思路:# 用戶輸入帳號密碼,從文件中讀出帳號密碼,與用戶輸入的進行比對# 附加:新建黑名單文件,同一個帳號名輸錯三次則將用戶名寫入黑名單文件中, # 若是用戶輸入的用戶名存在於黑名單中則直接退出# y=[]# z=[]# b=[]# tag=True# count=0# with open(r'db.txt', mode='rt', encoding='utf-8')as x,open(r'black.txt', mode='rt', encoding='utf-8')as a:# for data_name in x:# d_name = data_name.strip('\n').split(':')# y.append(d_name[0])# z.append(d_name[1])# for data_black_name in a:# b_name = data_black_name.strip('\n')# b.append(b_name)# while tag:# name=input('username>>>').strip()# if name in b:# print('黑名單用戶')# break# if name not in y:# print('用戶名不存在')# continue# while tag:# pwd = input('password>>>').strip()# if count>=2:# print('輸錯三次,已列爲黑名單')# with open(r'black.txt',mode='at',encoding='utf-8') as f:# f.write('%s\n' %name)# tag = False# break# if pwd not in z:# print('密碼不存在')# count+=1# else:# print('登陸成功')# tag=False# y=[]# z=[]# b=[]# tag=True# count=0# with open(r'db.txt', mode='rt', encoding='utf-8')as x,open(r'black.txt', mode='rt', encoding='utf-8')as a:# for data_name in x:# d_name = data_name.strip('\n').split(':')# y.append(d_name[0])# z.append(d_name)# print(z)# for data_black_name in a:# b_name = data_black_name.strip('\n')# b.append(b_name)# while tag:# name=input('username>>>').strip()# if name in b:# print('黑名單用戶')# break# if name not in y:# print('用戶名不存在')# continue# while tag:# pwd = input('password>>>').strip()# if count>2:# print('輸錯三次,已列爲黑名單')# with open(r'black.txt',mode='at',encoding='utf-8') as f:# f.write('%s\n' %name)# tag = False# break# if [name,pwd] not in z:# print('密碼不存在')# count+=1# else:# print('登陸成功')# tag=False