i am trying to set custom validator for login form but it always show that 'username and password are incorrect' even when i put the valid ones. Any suggestions? here is my code:
def login_check(form,field):
user_email = User.query.filter_by(email=form.email.data).first()
if user_email is None:
raise ValidationError('Username or password is incorrect')
elif not check_password_hash(field.data, user_email.password):
raise ValidationError('Username or password is incorrect')
class LoginForm(FlaskForm):
email = StringField('Email', validators=[InputRequired(), Email()])
password = PasswordField('Password', validators=[InputRequired(),login_check])
submit = SubmitField('Login')