寫一個注冊的小程序,賬號和密碼都存在文件里面


2、寫一個注冊的程序,賬號和密碼都存在文件里面。
choice = input('請輸入你的選擇:1,注冊2、刪除用戶3、登錄')
注冊
輸入
賬號
密碼
密碼確認
#需要校驗用戶是否存在,兩次輸入的密碼,是否一致,為空的情況
賬號和密碼都存在文件里面
刪除
輸入一個用戶名
需要校驗用戶是否存在
登錄
輸入賬號密碼登錄

user_info = {} #存放所有的用戶
with open('users.txt') as f:
for line in f:
# niuhanyang,123456\n
line = line.strip()
temp = line.split(',')
username = temp[0]
pwd = temp[1]
user_info[username]=pwd
for i in range(3):
choice = input('請輸入你的選擇'
'1、登錄 2、注冊 3、刪除').strip()
if choice=='1':
username = input('username:').strip()
pwd = input('pwd:').strip()
if username and pwd:
if username in user_info:
if user_info.get(username)==pwd:
print('登錄成功')
else:
print('賬號密碼錯誤!')
else:
print("user not found!")
else:
print('賬號密碼不能為空!')
elif choice=='2':
username = input('username:').strip()
pwd = input('pwd:').strip()
cpwd = input('cpwd:').strip()
if username and pwd and cpwd:
if username in user_info:
print('該用戶已經被注冊!')
else:
if pwd==cpwd:
user_info[username]=pwd
print('恭喜,注冊成功!')
else:
print('兩次輸入的密碼不一致!')
else:
print('不能為空!')
elif choice=='3':
username = input('username:').strip()
if username:
if username in user_info:
user_info.pop(username)
print('刪除成功!')
else:
print('不能為空!')
else:
print("輸入有誤,請重新輸入")
else:
with open('users.txt','w') as fw:
for uname,pwd in user_info.items():
fw.write(uname+','+pwd+'\n')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM