Note that there are some explanatory texts on larger screens.

plurals
  1. POmy script (as shown) is not logging in properly?
    primarykey
    data
    text
    <p>My python script, with tkinter and sqlite3:</p> <pre><code>#! /usr/bin/python from 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` FROM `users` WHERE `username` = ? AND `password` = ?", (username_val_, password_en)) rows = 0 for 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 INTO users (username, password) VALUES(?, ?)", (username, new_pass)) conn.commit() def run_test(): username_val = username.get() password_val = password.get() if len(username_val)&gt;0 and len(password_val)&gt;0: error_textv.set("") join(username_val, password_val) suc_textv.set("Well done!") else: error_textv.set("All fields are 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() </code></pre> <p>As you will see, my code is very badly written, and messy. On the login function, i was hoping that it would set "user_session" to the username, which it does, but the if statement "if user_session = "None": then the whole login page is shown, but when i set the variable to the login username the login page stays, instead of printing "welcome"...any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload