initial login logic
This commit is contained in:
48
forms.py
Normal file
48
forms.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import re
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, HiddenField
|
||||
from wtforms.validators import (
|
||||
DataRequired, Email, EqualTo, Length, ValidationError
|
||||
)
|
||||
|
||||
|
||||
def strong_password(form, field):
|
||||
"""Validate password meets strong requirements."""
|
||||
password = field.data
|
||||
errors = []
|
||||
|
||||
if len(password) < 8:
|
||||
errors.append("at least 8 characters")
|
||||
if not re.search(r'[A-Z]', password):
|
||||
errors.append("an uppercase letter")
|
||||
if not re.search(r'[a-z]', password):
|
||||
errors.append("a lowercase letter")
|
||||
if not re.search(r'\d', password):
|
||||
errors.append("a number")
|
||||
if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
|
||||
errors.append("a special character (!@#$%^&*(),.?\":{}|<>)")
|
||||
|
||||
if errors:
|
||||
raise ValidationError(f"Password must contain {', '.join(errors)}.")
|
||||
|
||||
|
||||
class SignupForm(FlaskForm):
|
||||
email = StringField('Email', validators=[
|
||||
DataRequired(message="Email is required."),
|
||||
Email(message="Please enter a valid email address."),
|
||||
Length(max=255, message="Email must be less than 255 characters.")
|
||||
])
|
||||
|
||||
password = PasswordField('Password', validators=[
|
||||
DataRequired(message="Password is required."),
|
||||
strong_password
|
||||
])
|
||||
|
||||
confirm_password = PasswordField('Confirm Password', validators=[
|
||||
DataRequired(message="Please confirm your password."),
|
||||
EqualTo('password', message="Passwords must match.")
|
||||
])
|
||||
|
||||
altcha = HiddenField('altcha', validators=[
|
||||
DataRequired(message="Please complete the CAPTCHA challenge.")
|
||||
])
|
||||
Reference in New Issue
Block a user