我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用werkzeug.generate_password_hash()。
def register(): """Registers the user.""" if g.user: return redirect(url_for('home.timeline')) error = None if request.method == 'POST': if not request.form['username']: error = 'You have to enter a username' elif not request.form['email'] or \ '@' not in request.form['email']: error = 'You have to enter a valid email address' elif not request.form['password']: error = 'You have to enter a password' elif request.form['password'] != request.form['password2']: error = 'The two passwords do not match' elif db.session.query(User).filter_by(username=request.form['username']).first() is not None: error = 'The username is already taken' else: user = User(request.form['username'], request.form['email'], generate_password_hash(request.form['password'])) db.session.add(user) db.session.commit() flash('You were successfully registered and can login now') return redirect(url_for('users.login')) return render_template('register.html', error=error)
def set_password(self, password): self.passwdhash = generate_password_hash(password)
def generate_password_hash(self, password): return generate_password_hash(password)
def create_user(attempt, form): u = User(form.name.data, attempt.email, generate_password_hash(form.password.data)) db.session.add(u) db.session.delete(attempt) db.session.commit()
def set_password(self, password): self.password = generate_password_hash(password)
def set_password(self, password): self.pwdhash = generate_password_hash(password)