Python wtforms.PasswordField() Examples

The following are 8 code examples of wtforms.PasswordField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wtforms , or try the search function .
Example #1
Source File: forms.py    From sample-platform with ISC License 6 votes vote down vote up
def valid_password(form: CompleteSignupForm, field: PasswordField) -> None:
    """
    Check for validity of a password.

    :param form: The form which is being passed in
    :type form: Form
    :param field: The data value for the 'password' inserted by User
    :type field : PasswordField
    """
    from run import config
    min_pwd_len = int(config['MIN_PWD_LEN'])
    max_pwd_len = int(config['MAX_PWD_LEN'])
    pass_size = len(field.data)
    if pass_size == 0:
        raise ValidationError('new password cannot be empty')
    if pass_size < min_pwd_len or pass_size > max_pwd_len:
        raise ValidationError(
            f'Password needs to be between {min_pwd_len} and {max_pwd_len} characters long (you entered {pass_size})'
        ) 
Example #2
Source File: views.py    From Flask-Framework-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def scaffold_form(self):
        form_class = super(UserAdminView, self).scaffold_form()
        form_class.password = PasswordField('Password')
        form_class.new_password = PasswordField('New Password')
        form_class.confirm = PasswordField('Confirm New Password')
        return form_class 
Example #3
Source File: admin.py    From maple-blog with GNU General Public License v3.0 5 votes vote down vote up
def scaffold_form(self):
        form_class = super(UserView, self).scaffold_form()
        form_class.password = PasswordField(
            "Password", [DataRequired(), Length(min=4, max=20)])
        return form_class 
Example #4
Source File: forms.py    From sample-platform with ISC License 5 votes vote down vote up
def validate_password_repeat(form: CompleteSignupForm, field: PasswordField) -> None:
        """
        Validate if the repeated password is the same as 'password'.

        :param form: The form which is being passed in
        :type form: CompleteSignupForm
        :param field : The data value for the 'password' entered by User
        :type field : PasswordField
        """
        if field.data != form.password.data:
            raise ValidationError('The password needs to match the new password') 
Example #5
Source File: forms.py    From sample-platform with ISC License 5 votes vote down vote up
def validate_current_password(form, field) -> None:
        """
        Validate current password entered with the password stored in database.

        :param form: The form which is being passed in
        :type form: AccountForm
        :param field: The data value for the 'password' entered by User
        :type field : PasswordField
        """
        if form.user is None:
            raise ValidationError('User instance not passed to form validation')

        if not form.user.is_password_valid(field.data):
            raise ValidationError('Invalid password') 
Example #6
Source File: forms.py    From sample-platform with ISC License 5 votes vote down vote up
def validate_new_password(form, field) -> None:
        """
        Validate the new password entered.

        :param form: The form which is being passed in
        :type form: AccountForm
        :param field: The data value for the 'password' entered by User
        :type field : PasswordField
        """
        if len(field.data) == 0 and len(form.new_password_repeat.data) == 0:
            return

        valid_password(form, field) 
Example #7
Source File: user.py    From betterlifepsi with MIT License 4 votes vote down vote up
def scaffold_form(self):
        # Start with the standard form as provided by Flask-Admin. We've already told Flask-Admin to exclude the
        # password field from this form.
        form_class = super(UserAdmin, self).scaffold_form()

        # Add a password field, naming it "password2" and labeling it "New Password".
        # autocomplete:new-password is to disable chrome to autofill password
        # Reference: http://stackoverflow.com/questions/15738259/disabling-chrome-autofill
        form_class.password2 = PasswordField(label=lazy_gettext('New Password'),
                                             render_kw={"autocomplete": "new-password"},
                                             description=lazy_gettext('Left blank if you don\'t want to change it, '
                                                                      'input the new password to change it'))
        return form_class 
Example #8
Source File: forms.py    From sample-platform with ISC License 4 votes vote down vote up
def validate_new_password_repeat(form, field) -> None:
        """
        Validate new password repeat and checks if it matches 'new_password'.

        :param form: The form which is being passed in
        :type form: AccountForm
        :param field: The data value for the 'password' entered by User
        :type field : PasswordField
        """
        if form.email is not None:
            if len(field.data) == 0 and len(form.new_password.data) == 0:
                return

        if field.data != form.new_password.data:
            raise ValidationError('The password needs to match the new password')