我正在尝试在我的python网络应用中实现一个登录/注册/注销元素。我正在使用Flask。我正在使用bcrypt来对密码进行哈希处理和加盐,但始终收到此错误:TypeError:需要一个类似字节的对象,而不是'RowProxy'。密码肯定会存储在哈希和盐中。但不允许用户登录。
@app.route("/searchPage", methods=['POST','GET'])
def loggingin():
title = "Search"
#get request form variables
username = request.form.get('username')
if db.execute("SELECT username FROM users WHERE username = :username",{"username": username}).rowcount == 0:
return render_template("login.html", message="invalid username, please try again.")
hashed_password = db.execute("SELECT username, password FROM users WHERE username = :username",{"username": username}).fetchone()
if bcrypt.checkpw(request.form.get('password'), hashed_password):
return render_template("searchPage.html", title=title)
else:
return render_template("login.html", message="Incorrect Password.")
我的html是:
{% extends "nav.html" %}
{% block body %}
<main>
<h1>{{ message }}</h1>
<h3>Log In </h3>
<form action="{{ url_for('loggingin') }}" method="POST">
<div class="form-group">
<label>Username</label>
<input class="form-control" type="text" name="username">
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" type="password" name="password">
</div>
<button class="btn btn-success" type="submit">Log In</button>
</form>
</main>
{% endblock %}
db.execute(“ SELECT用户名,来自用户的密码,其中username =:username”,{“ username”:用户名})。fetchone()['password']
差异是此行末尾的['password']。 @mechanical_meat