![](/img/trans.png)
[英]How do I connect to a local postgres database without password from a script within Apache
[英]How do i get the password from the SQL database without it quoting the output?
我现在的代码是
import mysql.connector import hashlib
cnx = mysql.connector.connect(user='root', password='!Joshua1',
host='127.0.0.1',
database='passwordhashtest')
cursor = cnx.cursor()
Password = input("Enter the password >>")
hashpass = hashlib.md5(Password.encode('utf8')).hexdigest()
Email=input("number")
passwordcheck='''SELECT b FROM password2 WHERE a = %s AND b = %s'''
values=(Email,hashpass)
cursor.execute(passwordcheck,values)
hashedpassindatabase=cursor.fetchone()
print(hashedpassindatabase)
if hashedpassindatabase==hashpass:
print("Success!") else:
print("error")`
我的输出结果如下:
('d1133275ee2118be63a577af759fc052',)
error
看我的问题是引号和逗号! 我该如何删除它!?!?!??!
似乎不可能,我尝试了我能想到的一切!
hashpass 存储为
d1133275ee2118be63a577af759fc052
如果我从 mysql 获得的数据不包括引号和逗号,那么事情会很容易得到验证,但事实并非如此。 那是我不明白的!!!!!!!!! 帮助!!!!!!!!!!!!
DB API2 兼容cursor.fetchone()
的返回值是一个序列(或None
)。
在您的情况下,结果是一个包含单个项目的元组:
t = ('d1133275ee2118be63a577af759fc052',)
要访问此项目,请使用t[0]
。
或者坚持你的变量名:
hashedpassindatabase = ('d1133275ee2118be63a577af759fc052',)
actual_value = hashedpassindatabase[0]
print(actual_value)
输出:
d1133275ee2118be63a577af759fc052
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.