[英]How to check hashed password stored in PSQL DB
I want to verify the password by hashing it and then checking the hash on the PSQL DB 我想通过对密码进行哈希处理然后在PSQL DB上检查哈希来验证密码
I am trying to compare the hashes - but I am getting an error of Invalid Salt.
我正在尝试比较哈希值-但我收到了Invalid Salt.
错误Invalid Salt.
Here is my code: 这是我的代码:
@app.route("/hello", methods=["POST", "GET"])
def hello():
email = request.form.get("email")
password = request.form.get("password")
password = bcrypt.generate_password_hash(password).decode('utf-8')
db.execute("INSERT INTO users (email, password) VALUES (:email,
:password)",{"email": email, "password": password})
db.commit()
AND 和
@app.route("/check", methods=["POST", "GET"])
def check():
email = request.form.get("login_email")
check_email_in_db = db.execute("SELECT COUNT(*) FROM users WHERE email = :email", {"email": email}).fetchall()
if check_email_in_db[0][0] == 1 :
email = request.form.get("login_email")
password = request.form.get("login_password")
retrive_password_from_db = db.execute("SELECT password FROM
users WHERE email = :email", {"email": email}).fetchall()
retrive_password_from_db = retrive_password_from_db[0][0]
if bcrypt.check_password_hash(password, retrive_password_from_db):
return("this works")
else:
return("something is wrong")
OK, I figured it out. 好,我知道了。 All I had to do was, specify the rounds while hashing: 我要做的就是在散列时指定回合:
password = bcrypt.generate_password_hash(password, 10).decode('utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.