Reputation: 153
I have the following code:
password_master = str(self.master_password.text())
username = str(self.comboBox.currentText())
result = c.execute("SELECT * FROM register_table WHERE MASTER = '"+password_master+"' AND USERNAME = '"+username+"'")
if (len(result.fetchall()) > 0):
print("user found")
password_check = c.execute("SELECT PASSWORD FROM register_table WHERE USERNAME = '"+username+"' AND MASTER = '"+password_master+"'").fetchall()
password = str(password_check)
login(username, password)
From the "password_check" query I would like to extract only the text, because I need to pass variable "password" to "login" function. I tried everything but I always receive the following output:
[(u'@-passwordtest-@',)]
Is there a way to extract simply
passwordtest
Many thanks in advance!!!
Upvotes: 1
Views: 1144
Reputation: 4549
First off, I'll start with the standard SQL Injection warning. Granted, this doesn't look like it's web facing, but still. You should be using bind variables.
Secondly, your query will return an array of values, so you're trying to run the str() function on an array that contains strings. I would replace the lines:
password_check = c.execute("SELECT PASSWORD FROM register_table WHERE USERNAME = '"+username+"' AND MASTER = '"+password_master+"'").fetchall()
password = str(password_check)
with:
results = c.execute("SELECT PASSWORD FROM register_table WHERE USERNAME = '"+username+"' AND MASTER = '"+password_master+"'").fetchone()
password = results[0]
Upvotes: 3