def post(self): user = User.query.filter_by(email=self.data.get('email')).first() if user and bcrypt.check_password_hash(user.password, self.data.get('password')): return {'user': {'email': user.email}, 'token': user.token} else: return {'message': 'Please enter correct email and password.'}, 400
def check_user_password(username: str, password: str): # 检查用户密码,返回一个元组 (检查结果(Bool),提示信息) user = is_existing_user(username) if user and bcrypt.check_password_hash(user.password, password): return True, "登陆成功" else: return False, "用户不存在或密码错误"
def login(): form = LoginForm() if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(email = form.login_email.data).first() if user is not None and bcrypt.check_password_hash(user.password, form.login_password.data): flash('You were logged in.') login_user(user) return redirect(url_for('assets.viewassets')) else: flash('Incorrect username or password.') return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) # if a link is clicked that requires a user to be logged in, this will redirect to that link after login otherwise 'main.home' next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('main.home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Login failed, please check email and password.', 'danger') return render_template('login.html', title='Login', form=form)
def set_user(uid, origin_password, username=None, new_password=None, email=None): user = is_existing_user(uid=uid) if user and bcrypt.check_password_hash(user.password, origin_password): if username: if is_existing_user(username): return False, "用户已存在" user.username = username if new_password: user.password = bcrypt.generate_password_hash(new_password) if email: if is_existing_email(email): return False, "邮箱已注册" user.email = email db.session.commit() return True, "更新用户信息成功" else: return False, "用户不存在或密码错误"
def post(self): form = LoginForm() if form.validate_on_submit(): admin = get_admin_by_username(form.username.data) if admin: if bcrypt.check_password_hash(admin.password, form.password.data): token = jwt.encode( { 'user': admin.username, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=30) }, app.config['ADMIN_TOKEN_SECRET_KEY']).decode('UTF-8') return {'success': True, 'token': token} else: return { 'success': False, "errors": { "password": ["Senha incorreta."] } } else: return { 'success': False, "errors": { "username": ["Username não cadastrado."] } } else: return {'success': False, "errors": form.errors}
def app_login(): if current_user.is_authenticated: return redirect(url_for("home")) _form = LoginForm() if _form.validate_on_submit(): user = db.session.query(User).filter( User.username == _form.username.data).first() if user and bcrypt.check_password_hash(user.password, _form.password.data): login_user(user, remember=False) flash("Logged in successfully!", "success") return redirect(url_for("home")) flash("Username or password incorrect! Please try again...", "danger") return render_template('pages/login.html', form=_form)
def post(self): form = LoginForm() if form.validate_on_submit(): obj = get_by_email("*****@*****.**") if obj: if bcrypt.check_password_hash(obj.password, form.password.data): token = jwt.encode( { 'user': obj.email, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=30) }, app.config['MANAGER_TOKEN_SECRET_KEY']).decode('UTF-8') return {'success': True, 'token': token} else: return { 'success': False, "errors": { "password": ["Senha incorreta."] } } else: return { 'success': False, "errors": { "email": ["Email não cadastrado."] } } else: return {'success': False, "errors": form.errors}
def login(): if current_user.is_authenticated: return redirect(url_for("users.account_home")) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for("users.account_home")) else: flash('Login Error. Please check Username and Password', "danger") return render_template("login.html", form=form)
def check_password(self, password): return bcrypt.check_password_hash(self.password_hash, password)
def checkAuthenticator(self, plaintext_authenticator): if self.authenticator is None or self.authenticator == "": return False else: return bcrypt.check_password_hash(self.authenticator, plaintext_authenticator)
def checkAuthentification(self, plaintext_authentification): return bcrypt.check_password_hash(self.authentification, plaintext_authentification)
def checkAuthenticator(self, plaintext_authenticator): return bcrypt.check_password_hash(self.authenticator, plaintext_authenticator)
def login_user(model, payload): user = model.query.filter_by(Email=payload["email"]).first() if user and bcrypt.check_password_hash(user.password, payload["password"]): return user return None
def checkPassword(self, plaintext_password): return bcrypt.check_password_hash(self.password, plaintext_password)
def checkPin(self, plaintext_pin): if self.pin is None or self.pin == "": return False else: return bcrypt.check_password_hash(self.pin, plaintext_pin)
def validate_password(self, password): if password.data: if not bcrypt.check_password_hash(current_user.password, password.data): raise ValidationError( 'That password is incorrect. Please try again.')