>我有这个代码,我想将密码转换为md5
class UserLogin(Resource):
def post(self):
# Parse the arguments
parser = reqparse.RequestParser()
parser.add_argument('username')
parser.add_argument('password')
args = parser.parse_args()
_user = args['username']
_userPassword = args['password']
_h = hashlib.md5(_userPassword.encode())
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute('''select * from user where username = %s && password = %s''', (_user, _h))
data = cursor.fetchall()
return jsonify(data)
但错误说:h = hashlib.md5(_userPassword.encode((( 属性错误:"NoneType"对象没有属性"编码">
当我从哈希库中删除 encode(( 时,错误返回为:_h = hashlib.md5(_userPassword( 类型错误:需要支持缓冲区 API 的对象
请帮助我。 IM 使用 python3.6
而不是
_h = hashlib.md5(_userPassword.encode())
你可能想要
_h = hashlib.md5(_userPassword.encode()).hexdigest()
如果您存储密码的 MD5 哈希,则
password = md5(%s)
部分 如果您绑定_h
查询,则查询将不匹配。