def handle_login(form): def show_safe_err(err): if "@" in username: flash("Incorrect email or password", "danger") else: flash(err, "danger") username = form.username.data.strip() user = User.query.filter( or_(User.username == username, User.email == username)).first() if user is None: return show_safe_err("User {} does not exist".format(username)) if not check_password_hash(user.password, form.password.data): return show_safe_err("Incorrect password. Did you set one?") if not user.is_active: flash("You need to confirm the registration email", "danger") return addAuditLog(AuditSeverity.USER, user, "Logged in using password", url_for("users.profile", username=user.username)) db.session.commit() if not login_user(user, remember=form.remember_me.data): flash("Login failed", "danger") return return post_login(user, request.args.get("next"))
def change_password(): form = ChangePasswordForm(request.form) if form.validate_on_submit(): if check_password_hash(current_user.password, form.old_password.data): ret = handle_set_password(form) if ret: return ret else: flash("Old password is incorrect", "danger") return render_template("users/change_set_password.html", form=form, suggested_password=genphrase(entropy=52, wordset="bip39"))