0

I'm having a problem when trying to verify credentials ( I will post the code below ). I was wondering if it's happening because I stored username and password as a string within the database, should I have stored it as an integer?

The problem: I think it's easier to simply give an example of what the problem is, maybe it's easier to understand.

Information that is correct ( username = something and password = testing )

Example 1: You input "something" as username and "password" as password - that's fine it works, HOWEVER the next example is where things go wrong.

Example 2: You input the username "somethingfpsadadoia" and the password "testing" - the program will say it's correct as long as the password is correct. So as long as you have part of the username under username entry then the password works, but anything after that is not taken in consideration to say it's actually wrong.

Much appreciated if anyone can help !

""" def Is_Valid():

UsernameValidity=UserName_Entry.get()        
PasswordValidity=Password_Entry.get()
cursor.execute('''SELECT password FROM users WHERE username = ?''', (UsernameValidity,))
cursor.execute('''SELECT username FROM users WHERE password = ?''', (PasswordValidity,))
LogInAttempt = cursor.fetchone()
print (Is_Valid) # Testing to see if it works on shell
if LogInAttempt:
    print (" One of the accounts have successfully logged in ")
    IsValidText.config(text=" You have logged in! ", fg="black", highlightthickness=1)
    myGUI.after(1000, CoreContent) # Ignore this one for now.
else:
    print (" One of the accounts inputted the wrong credentials! ")
    IsValidText.config(text=" Invalid username or Password! ", fg="black", highlightthickness=1)

"""

1 Answer 1

1

You are executing two entirely independent queries. The second call to execute throws away any results from the first one; what you fetch from cursor is the result of the second query.

You have to tell the database to check both values when looking at each row:

cursor.execute('SELECT 1 FROM users WHERE username = ? AND password = ?',
               [UsernameValidity, PasswordValidity])
LogInAttempt = cursor.fetchone()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.