python - my script (as shown) is not logging in properly? -
my python script, tkinter , sqlite3:
#! /usr/bin/python tkinter import * import hashlib import sqlite3 conn = sqlite3.connect("test.db") query = conn.cursor() root = tk() root.geometry("800x800+10+10") root.title('test') user_session = "none" def login(): username_val_ = username_.get() password_val_ = password_.get() password_en = hashlib.sha512(password_val_).hexdigest() query.execute("select `username` `users` `username` = ? , `password` = ?", (username_val_, password_en)) rows = 0 user in query: rows = rows +1 final_name_ = user if rows == 1: final_name = final_name_[0] user_session = final_name print(user_session) if user_session == "none": username_l = label(root, text= "username:") username_l.place(x=20, y=0) username = entry(root) username.place(x=20, y=20) password_l = label(root, text= "password:") password_l.place(x=20, y=50) password = entry(root, show="*") password.place(x=20, y=70) def clear_fields(): username.delete(0, end) password.delete(0, end) def clear_fields_(): username_.delete(0, end) password_.delete(0, end) def join(username, password): new_pass = hashlib.sha512(password).hexdigest() print(new_pass) query.execute("insert users (username, password) values(?, ?)", (username, new_pass)) conn.commit() def run_test(): username_val = username.get() password_val = password.get() if len(username_val)>0 , len(password_val)>0: error_textv.set("") join(username_val, password_val) suc_textv.set("well done!") else: error_textv.set("all fields required") button = button(root, text = "reset", command = clear_fields) button.place(x=120, y=100) button = button(root, text = "register", command = run_test) button.place(x=20,y=100) error_textv = stringvar() error_textv.set("") error_text = label(root, textvariable= error_textv, fg = 'red') error_text.place(x=40,y=140) suc_textv = stringvar() suc_textv.set("") suc_text = label(root, textvariable= suc_textv, fg = 'green') suc_text.place(x=40,y=140) suc_text = label(root, text = 'or') suc_text.place(x=400,y=50) username_l_ = label(root, text= "username:") username_l_.place(x=600, y=0) username_ = entry(root) username_.place(x=600, y=20) password_l_ = label(root, text= "password:") password_l_.place(x=600, y=50) password_ = entry(root, show="*") password_.place(x=600, y=70) button_ = button(root, text = "reset", command = clear_fields_) button_.place(x=700, y=100) button_ = button(root, text = "login", command = login) button_.place(x=600,y=100) else: print "welocme" photo = photoimage(file="email.gif") w = label(root, image=photo) w.photo = photo w.place(x=300, y = 600) root.mainloop()
as see, code badly written, , messy. on login function, hoping set "user_session" username, does, if statement "if user_session = "none": whole login page shown, when set variable login username login page stays, instead of printing "welcome"...any ideas?
i believe (although not certain) user_session variable not beingness changed def login()
. instead def login()
creating new variable called user_session , not alter current user_session. should take @ global variables , how utilize them. global variables , how utilize them
python sqlite
No comments:
Post a Comment