我想創建一個登錄,其中將打開一個文本/ csv文件從文件中讀取「有效」用戶名和密碼,然後如果用戶添加的內容與文件中的內容匹配然後它會允許訪問程序的其餘部分用戶名和密碼登錄
我怎麼會下面的代碼集成到其中一個打開文件中讀取有效的用戶名和密碼,並檢查其對用戶輸入
目前,我有有效的東西,但只有一個密碼,我已經在代碼中設置。
Password = StringVar()
Username = StringVar()
def EnterPassword():
file = open('Logins.txt', 'w') #Text file i am using
with open('Logins.txt') as file:
data = file.read() #data=current text in text file
UsernameAttempt = Username.get()#how to get value from entry box
PasswordAttempt = Password.get()#how to get value from entry box
if PasswordAttempt == '' and UsernameAttempt == '':
self.delete()
Landlord = LandlordMenu()
else:
PasswordError = messagebox.showerror('Password/Username Entry','Incorrect Username or Password entered.\n Please try again.')
PasswordButton = Button(self.GenericGui,text = 'Landlord Section',height = 3, width = 15, command = EnterPassword, font = ('TkDefaultFont',14),relief=RAISED).place(x=60,y=175)
一些幫助,將不勝感激
你需要什麼樣的幫助?您的問題不包括實際問題。 –
@BryanOakley Id喜歡整合我目前使用的代碼,因此它會檢查用戶的用戶名和密碼輸入是否符合「有效登錄」文件。所有可能的登錄名將被存儲在text/csv文件中,而不是僅在代碼中設置用戶名和密碼,我目前有 – Ross
在給定的代碼中,沒有任何嘗試從文件或類似文件中讀取任何內容。你應該做的是:從文件讀取,分配id和pass.es到各自的列表,並檢查輸入的是否在這些列表中。首先嚐試實現這一點,然後問關於你卡住的步驟或獲取錯誤等 – Lafexlos