作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想通过散列来验证密码,然后检查 PSQL DB 上的散列
我正在尝试比较哈希 - 但我收到了 Invalid Salt.
这是我的代码:
@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()
和
@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")
最佳答案
好的,我明白了。我所要做的就是在散列时指定轮数:
password = bcrypt.generate_password_hash(password, 10).decode('utf-8')
关于python - 如何检查存储在 PSQL DB 中的散列密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54757448/
我是一名优秀的程序员,十分优秀!