old_contents: from flask_wtf import FlaskForm
  from wtforms import StringField, BooleanField, PasswordField
  from wtforms.validators import DataRequired
  
  
  class LoginForm(FlaskForm):
      username = StringField('username', validators=[DataRequired()])
      password = PasswordField('password', validators=[DataRequired()])
      remember_me = BooleanField('remember_me', default=False)
  
  class SignupForm(FlaskForm):
      username = StringField('username', validators=[DataRequired()])
      password = PasswordField('password', validators=[DataRequired()])
      password2 = PasswordField('password2', validators=[DataRequired()])
  
new_contents: from flask_wtf import FlaskForm
  from wtforms import StringField, BooleanField, PasswordField
  from wtforms.validators import DataRequired, ValidationError, EqualTo
  from .models import User
  
  
  class LoginForm(FlaskForm):
      username = StringField('username', validators=[DataRequired()])
      password = PasswordField('password', validators=[DataRequired()])
      remember_me = BooleanField('remember_me', default=False)
  
  
  class SignupForm(FlaskForm):
      username = StringField('username', validators=[DataRequired()])
      password = PasswordField('password', validators=[DataRequired()])
      password2 = PasswordField('password2', validators=[DataRequired(), EqualTo('password')])
  
      def validate_username(self, username):
          user = User.query.filter_by(username=username.data).first()
          if user is not None:
              raise ValidationError('Username already in use. Please use a different username.')
  
subject: Validate username and password on signup