簡體   English   中英

在Tkinter GUI中使用密碼術

[英]Using Cryptography with Tkinter GUI

因此,我一直在做一些有關創建約會預定系統的課程,目前正在調查員工的登錄信息。 我希望能夠加密員工的密碼以進行存儲和比較。

我的問題是我必須從“輸入”框中獲取密碼,但是結果我不知道如何將數據轉換為字節,以便可以對其進行加密。 這是我目前所擁有的:

import tkinter as tk
from cryptography.fernet import Fernet

key = Fernet.generate_key()
cipher_suite = Fernet(key)

MEDIUM_FONT = ("Berlin Sans FB", 12)
LARGE_FONT = ("Berlin Sans FB", 16)

#validate function
def validateStylist(window):
    password = bstr(passwordEntry.get())
    cipher_text = cipher_suite.encrypt(password)
    plain_text = cipher_suite.decrypt(cipher_text)
    print(plain_text)

window = tk.Tk()

titleLabel = tk.Label(window, text="Register Stylist", font=LARGE_FONT, bg="#FFC0CB")
titleLabel.grid(columnspan = 4)

#Password
passwordLabel = tk.Label(window, text="Password:", font=MEDIUM_FONT, bg="#FFC0CB")
passwordLabel.grid(row=1,column=3)
passwordVar = tk.StringVar(window)
passwordEntry = tk.Entry(window, textvariable=passwordVar)
passwordEntry.grid(row=2,column=3)

finishButton = tk.Button(window, text="Finish",
                          command=validateStylist(window))
finishButton.grid(row=4, column=3, sticky="ew")

window.mainloop()

您可以在將字符串傳遞給加密之前將其編碼為utf-8:

password = passwordEntry.get().encode("utf-8")
cipher_text = cipher_suite.encrypt(password)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM