第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python 登錄屏幕 - 如何驗(yàn)證 json 文件中的密碼?

Python 登錄屏幕 - 如何驗(yàn)證 json 文件中的密碼?

皈依舞 2021-06-23 18:19:10
我正在編寫(xiě)一個(gè)要求用戶名和密碼的登錄屏幕。一旦我讓這個(gè)屏幕正常工作,我計(jì)劃將它添加到我正在處理的更大程序的開(kāi)頭。我目前遇到的問(wèn)題是我無(wú)法驗(yàn)證特定用戶的密碼。現(xiàn)在,程序?qū)z查用戶名是否已存在,如果存在,則將檢查密碼是否存在。問(wèn)題是有人可以輸入另一個(gè)用戶名和自己的密碼,然后登錄到其他人的帳戶。安全性對(duì)我的程序來(lái)說(shuō)不是什么大問(wèn)題(我只是在制作一個(gè)多鄰國(guó)類型的語(yǔ)言應(yīng)用程序),但這是一個(gè)非常明顯的問(wèn)題,我想弄清楚如何解決。from tkinter import *import jsonclass LoginFrame(Frame):    def __init__(self, master):        super().__init__(master)        master.title("Login")        self.label_username = Label(self, text="Username")        self.label_password = Label(self, text="Password")        self.entry_username = Entry(self)        self.entry_username.focus()     #This sets the focus to the username entry box        self.entry_password = Entry(self, show="*")        self.label_username.grid(row=0, column=0)        self.label_password.grid(row=1, column=0)        self.entry_username.grid(row=0, column=1)        self.entry_password.grid(row=1, column=1)        self.login_button = Button(self, text="Login", command=self.Login)        self.login_button.grid(columnspan=2)        self.grid()    def Login(self):        current_info = open ("C:\\LearningArabic\\LiblibArriby\\Usernames\\usernames.json").read()        username = self.entry_username.get()        password = self.entry_password.get()        if username in current_info:            print("Test")            if password in current_info:                print("Now we're talking")            else:                print("Well, you're trying")        else:       #This section appends the new username and password combo to the json file            usr = {username: password}            with open("C:\\LearningArabic\\LiblibArriby\\Usernames\\usernames.json") as a:                data = json.load(a)            data.update(usr)            with open("C:\\LearningArabic\\LiblibArriby\\Usernames\\usernames.json", "w") as a:                json.dump(data, a)root = Tk()lf = LoginFrame(root)root.mainloop()任何幫助將不勝感激,如果對(duì)代碼有其他評(píng)論,請(qǐng)不要退縮。我想學(xué)習(xí)——不僅僅是得到答案!
查看完整描述

1 回答

?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

保持您當(dāng)前的文件格式,我只會(huì)做類似的事情:


PATH_USERNAMES = "C:/LearningArabic/LiblibArriby/Usernames/usernames.json"


with open(PATH_USERNAMES) as fd:

  current_info = json.load(fd)


username = self.entry_username.get()

password = self.entry_password.get()


if username in current_info:

  saved_password = current_info.get(username, '')

  if password == saved_password:

    print("Password OK")

但強(qiáng)烈建議您保存散列的密碼并適當(dāng)更改驗(yàn)證......


查看完整回答
反對(duì) 回復(fù) 2021-06-29
  • 1 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)