使用散列烧瓶应用程序更新密码表单

Update password form with hashing flask application

我正在学习一门名为 python 的网络编程课程。我们学会了使用 web 框架 flask。我正在研究这个主题的项目,我已经使用烧瓶创建了一个应用程序。我已经制作了一个注册表单和登录表单,它们正在使用 SqlAlchemy 来创建数据库。现在,我不知道的是,当我创建用户、登录并使用更新表单更改其密码时,我似乎无法找到能够登录的方法。

我认为解决方案是散列密码,因为我的登录表单搜索散列密码,而我的更新视图不​​会创建密码。所以我的问题是如何在 user_change 视图中创建散列密码?

抱歉这个愚蠢的问题,但我对此还很陌生,我似乎迷失了方向。

是的,您可以使用 wtforms 和 sqlalchemy

class UpdateAccountForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired(), Length(min=2,max=20)])
    email = StringField('Email', validators=[DataRequired(), Email()])
    submit = SubmitField('Update')
@app.route("/account" , methods=['GET','Post'])
@login_required #This is from flask-login extension
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account.html', title="Account", form=form)

本教程可能对您有很大帮助https://www.youtube.com/watch?v=803Ei2Sq-Zs&