Python wtforms 模块,PasswordField() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用wtforms.PasswordField()

项目:sample-platform    作者:CCExtractor    | 项目源码 | 文件源码
def validate_current_password(form, field):
        """
        Validates 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 not None:
            if not form.user.is_password_valid(field.data):
                raise ValidationError('Invalid password')
        else:
            raise ValidationError('User instance not passed to form '
                                  'validation')
项目:sample-platform    作者:CCExtractor    | 项目源码 | 文件源码
def validate_new_password_repeat(form, field):
        """
        Validates 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:
            # Email form is present, so it's optional
            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')
项目:sample-platform    作者:CCExtractor    | 项目源码 | 文件源码
def valid_password(form, field):
    """
    Function to 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
    """
    if len(field.data) == 0:
        raise ValidationError('new password cannot be empty')
    if len(field.data) < 10 or len(field.data) > 500:
        raise ValidationError('Password needs to be between 10 and 500 '
                              'characters long (you entered %s characters'
                              % len(field.data))
项目:sample-platform    作者:CCExtractor    | 项目源码 | 文件源码
def validate_password_repeat(form, field):
        """
        Validates 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')
项目:sample-platform    作者:CCExtractor    | 项目源码 | 文件源码
def validate_new_password(form, field):
        """
        Validates 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)
项目:flask-boilerplate    作者:ItEngine    | 项目源码 | 文件源码
def scaffold_form(self):
        form_class = super(UserAdmin, self).scaffold_form()
        form_class.password = PasswordField()
        return form_class