日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python账号密码一一对应_python模拟用户登录系统,如何两个用户输入各自的密码才能登入?...

發布時間:2023/12/2 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python账号密码一一对应_python模拟用户登录系统,如何两个用户输入各自的密码才能登入?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

展開全部

#我可以把我自己2113的成果送你,你來研究5261研究

import json #用來存儲數據4102的模塊

import os #用來進行文件操作1653

import sys #獲取腳本所在目錄用

import re #用來進行字符串操作

script_path = os.path.realpath(__file__)

PATH = os.path.dirname(script_path)

contents_list = []

if not os.path.exists(PATH+'\\'+'user_information'):

os.mkdir(PATH+'\\'+'user_information')

#主體函數,是主要的內容

def main(user_name):

obj = input('你現在想要干什么?\n1.新建一個文件 2.查看一個文件 3.更改密碼 4.更改用戶名\n')

if obj == '1':

file_name = input('請輸入文件名(不用帶后綴名):')

print('請輸入文件內容(如果完成輸入的話就新建一行,然后輸入“輸入已完成”并回車來完成輸入,如:\n這是第一行\n這是第二行\n這是第\

三行\n這是文件的最后一行\n輸入已完成\n\n請輸入:')

while True:

contents = input()

if contents == '輸入已完成':

break

else:

contents_list.append(contents)

with open(PATH+'\\'+user_name+'.mmwj','r') as f:

file_names = f.readlines()

if file_name+'\n' in file_names:

print('害!寫了半天,你文件名還是重復了,害!')

input('按回車鍵退出……')

else:

with open(PATH+'\\'+user_name+'\\'+file_name+'.json','w') as f:

json.dump(contents_list,f)

with open(PATH+'\\'+user_name+'.mmwj','a') as f:

f.write(file_name+'\n')

print('已成功!')

input('按回車鍵退出……')

elif obj == '2':

with open(PATH+'\\'+user_name+'.mmwj','r') as f:

file_name_list = f.readlines()

temporary_file_name_list = []

for i in file_name_list:

i = re.sub('\"|\'','',i)

i = re.sub('\n','',i)

temporary_file_name_list.append(i)

file_name_list = temporary_file_name_list

if not file_name_list == []:

print('這是你存過的所有的文件的列表:')

for i in file_name_list:

print(i)

user_file_name = input('請輸入你想要查看的文件的文件名(不用帶后綴):')

if user_file_name in file_name_list:

with open(PATH+'\\'+user_name+'\\'+user_file_name+'.json','r') as f:

cont = json.load(f)

for i in cont:

print(i)

input('按回車鍵退出……')

else:

print('未找到此文件!')

input('按回車鍵退出……')

else:

print('空空如也……')

input('按回車鍵退出……')

elif obj == '3':

with open(PATH+'\\'+'user_information\\user_name_list.json','r') as n:

user_name_list_change = n.readlines()

tm_name_change = []

for i in user_name_list_change:

i = re.sub('\"\'','',i)

i = re.sub('\n','',i)

tm_name_change.append(i)

user_name_list_change = tm_name_change

with open(PATH+'\\'+'user_information\\user_password_list.json','r') as p:

user_password_list_change = p.readlines()

tm_password_change = []

for i in user_password_list_change:

i = re.sub('\"\'','',i)

i = re.sub('\n','',i)

tm_password_change.append(i)

user_password_list_change = tm_password_change

xyz = user_name_list_change.index('"'+user_name+'"')

old_right_password = user_password_list_change[xyz]

old_password = input('請輸入舊密碼:')

if '"' + old_password + '"' == old_right_password:

new_password = input('請輸入新密碼(不要帶引號或中文!):')

user_password_list_change[xyz] = new_password

with open(PATH+'\\'+'user_information\\user_password_list.json','w') as np:

for i in user_password_list_change:

np.write('"'+i+'"'+'\n')

print('密碼已更改!')

input('按回車鍵退出……')

else:

print('對不起,舊密碼錯誤。')

input('按回車鍵退出……')

elif obj == '4':

with open(PATH+'\\'+'user_information\\user_name_list.json','r') as n:

user_name_list_change = n.readlines()

tm_name_change = []

for i in user_name_list_change:

i = re.sub('\"\'','',i)

i = re.sub('\n','',i)

tm_name_change.append(i)

user_name_list_change = tm_name_change

xyz = user_name_list_change.index('"'+user_name+'"')

new_name = input('請輸入新用戶名:')

if '"' + new_name + '"' in user_name_list_change:

print('用戶名已存在。')

input('按回車鍵退出……')

else:

user_name_list_change[xyz] = '"' + new_name + '"'

os.rename(PATH+'\\'+user_name+'.mmwj',PATH+'\\'+new_name+'.mmwj')

os.rename(PATH+'\\'+user_name,PATH+'\\'+new_name)

with open(PATH+'\\'+'user_information\\user_name_list.json','w') as np:

for i in user_name_list_change:

np.write(i+'\n')

print('用戶名已更改!')

input('按回車鍵退出……')

#注冊函數

def sign_up():

user_name = input('請輸入用戶名(不要帶引號或中文!):')

user_password = input('請輸入密碼(不要帶引號或中文!):')

if user_name == 'user_information':

print('用戶名無效!')

input('按回車鍵退出……')

if not os.path.exists(PATH+'\\'+'user_information\\user_name_list.json'):

with open(PATH+'\\'+'user_information\\user_name_list.json','w') as con:

json.dump(user_name,con)

con.write('\n')

with open(PATH+'\\'+'user_information\\user_password_list.json','w') as con:

json.dump(user_password,con)

con.write('\n')

os.mkdir(PATH+'\\'+user_name)

with open(PATH+'\\'+user_name+'.mmwj','w') as f:

pass

print('賬戶創建成功 !')

main(user_name)

else:

with open(PATH+'\\'+'user_information\\user_name_list.json','r') as f:

unsul = f.readlines()

if '"' + user_name + '"\n' in unsul:

print('用戶名已存在。')

input('按回車鍵退出……')

else:

with open(PATH+'\\'+'user_information\\user_name_list.json','a') as con:

json.dump(user_name,con)

con.write('\n')

with open(PATH+'\\'+'user_information\\user_password_list.json','a') as con:

json.dump(user_password,con)

con.write('\n')

os.mkdir(PATH+'\\'+user_name)

with open(PATH+'\\'+user_name+'.mmwj','w') as f:

pass

print('賬戶創建成功 !')

main(user_name)

#內容函數

def content():

user_obj = input('請問你是想登錄,還是想注冊?(輸入1或2):')

if user_obj == '1':

if not os.path.exists(PATH+'\\'+'user_information\\user_name_list.json'):

print('對不起,你現在還沒有任何賬戶。')

yes_or_no = input('請問你要注冊一個賬戶嗎?(輸入要或不要):')

if yes_or_no == '要':

sign_up()

if yes_or_no == '不要':

input('按回車鍵退出……')

else:

with open(PATH+'\\'+'user_information\\user_name_list.json','r') as n:

name_list = n.readlines()

temporary_name_list = []

for i in name_list:

i = re.sub('\"|\'','',i)

i = re.sub('\n','',i)

temporary_name_list.append(i)

name_list = temporary_name_list

with open(PATH+'\\'+'user_information\\user_password_list.json','r') as p:

password_list = p.readlines()

temporary_password_list = []

for i in password_list:

i = re.sub('\"|\'','',i)

i = re.sub('\n','',i)

temporary_password_list.append(i)

password_list = temporary_password_list

contrast = dict(zip(name_list,password_list))

user_name = input('請輸入用戶名:')

if user_name not in name_list:

print('未找到此用戶名!')

input('按回車鍵退出……')

else:

password = input('請輸入密碼:')

xpassword = contrast[user_name]

if xpassword == password:

print('登錄成功!')

main(user_name)

else:

print('密碼輸入錯誤。')

input('按回車鍵退出……')

elif user_obj == '2':

sign_up()

content()

已贊過

已踩過<

你對這個回答的評價是?

評論

收起

總結

以上是生活随笔為你收集整理的python账号密码一一对应_python模拟用户登录系统,如何两个用户输入各自的密码才能登入?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。