Python django.contrib.auth.password_validation 模块,validate_password() 实例源码

我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用django.contrib.auth.password_validation.validate_password()

项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:WPS-3rd    作者:Fastcampus-WPS    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        # ?? ?? ???? ???
        # ???? ??? & ?????? ????? ??
        # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        password_validation.validate_password(
            self.cleaned_data['password2'],
            self.instance
        )
        return password2
项目:django_rest_example    作者:devslaw    | 项目源码 | 文件源码
def is_invalid_password(password, repeat_password):
    """
    check passwords strength and equality
    :param password:
    :param repeat_password:
    :return error message or None:
    """
    error_messages = {
        'not_match': 'Password and Repeat Password fields must match.',
    }

    if not password or (not password and not repeat_password):
        return

    error_message = ''
    try:
        password_validation.validate_password(password=password, )
    except forms.ValidationError as e:
        error_message = list(e.messages)

    if error_message:
        return forms.ValidationError(error_message)

    if password != repeat_password:
        return forms.ValidationError(error_messages['not_match'])
项目:km-api    作者:knowmetools    | 项目源码 | 文件源码
def validate_new_password(self, password):
        """
        Validate the user's new password.

        We validate the password by running it through Django's password
        validation system.

        Args:
            password (str):
                The password to validate.

        Returns:
            str:
                The validated password.

        Raises:
            ValidationError:
                If the password is not valid.
        """
        password_validation.validate_password(password)

        return password
项目:km-api    作者:knowmetools    | 项目源码 | 文件源码
def validate_password(self, password):
        """
        Validate the provided password.

        This runs the password through Django's password validation
        system.

        Args:
            password (str):
                The password to validate.

        Returns:
            str:
                The validated password.

        Raises:
            ValidationError:
                If the provided password does not pass Django's password
                validation checks.
        """
        password_validation.validate_password(password, self.instance)

        return password
项目:registration    作者:HackAssistant    | 项目源码 | 文件源码
def clean_password2(self):
        # Check that the two password entries match
        password = self.cleaned_data.get("password")
        password2 = self.cleaned_data.get("password2")
        if password and password2 and password != password2:
            raise forms.ValidationError("Passwords don't match")
        validate_password(password)
        return password2
项目:registration    作者:HackAssistant    | 项目源码 | 文件源码
def clean_new_password2(self):
        password1 = self.cleaned_data.get('new_password1')
        password2 = self.cleaned_data.get('new_password2')
        if password1 and password2:
            if password1 != password2:
                raise forms.ValidationError("The two password fields didn't match.")
        password_validation.validate_password(password2)
        return password2
项目:django-username-email    作者:tmm    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        if password_validation:
            self.instance.email = self.cleaned_data.get('email')
            password_validation.validate_password(self.cleaned_data.get('password2'), self.instance)
        return password2
项目:ava-website    作者:ava-project    | 项目源码 | 文件源码
def clean_password(self):
        password = self.cleaned_data.get('password')
        self.instance.username = self.cleaned_data.get('username')
        password_validation.validate_password(password, self.instance)
        return password
项目:rho-django-user    作者:freakboy3742    | 项目源码 | 文件源码
def validate_password(self, password, instance):
            pass
项目:rho-django-user    作者:freakboy3742    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        self.instance.username = self.cleaned_data.get('username')
        password_validation.validate_password(self.cleaned_data.get('password2'), self.instance)
        return password2
项目:verbes    作者:larose    | 项目源码 | 文件源码
def clean_password(self):
        password = self.cleaned_data['password']
        password_validation.validate_password(password, self.instance)
        return password
项目:Recruitment-Website    作者:ISTE-NITK    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        self.instance.username = self.cleaned_data.get('username')
        self.instance.email = self.cleaned_data.get('email')
        self.instance.first_name = self.cleaned_data.get('firstname')
        self.instance.last_name = self.cleaned_data.get('lastname')
        password_validation.validate_password(self.cleaned_data.get('password2'), self.instance)
        return password2
项目:django-twilio-tfa    作者:rtindru    | 项目源码 | 文件源码
def validate_password(password, user=None, password_validators=None):
        pass
项目:auction-backend    作者:luissalgadofreire    | 项目源码 | 文件源码
def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        self.instance.email = self.cleaned_data.get('email')
        password_validation.validate_password(self.cleaned_data.get('password2'), self.instance)
        return password2
项目:USTC-Software-2017    作者:igemsoftware2017    | 项目源码 | 文件源码
def validate_password(self, value):
        validate_password(value)

        return value
项目:USTC-Software-2017    作者:igemsoftware2017    | 项目源码 | 文件源码
def validate(self, data):

        new, new2 = data['new1'], data['new2']
        if new and new2 and new != new2:
            raise serializers.ValidationError(
                'New passwords mismatched!')

        validate_password(new)

        return data
项目:USTC-Software-2017    作者:igemsoftware2017    | 项目源码 | 文件源码
def validate_new_password(self, value):
        validate_password(value)

        return value
项目:sns_prj    作者:YongPilMoon    | 项目源码 | 文件源码
def validate(self, data):
        if data['password1'] != data['password2']:
            raise serializers.ValidationError("The two password fields didn't match.")
        errors = dict()
        try:
            password_validation.validate_password(password=data['password1'], user=CustomUser)
        except exceptions.ValidationError as e:
            errors['password'] = list(e.messages)

        if errors:
            raise serializers.ValidationError(errors)

        return data
项目:sns_prj    作者:YongPilMoon    | 项目源码 | 文件源码
def validate(self, data):
        if data['password1'] != data['password2']:
            raise serializers.ValidationError("The two password fields didn't match.")
        errors = dict()
        try:
            password_validation.validate_password(password=data['password1'], user=CustomUser)
        except exceptions.ValidationError as e:
            errors['password'] = list(e.messages)

        if errors:
            raise serializers.ValidationError(errors)

        return data
项目:Vataxia    作者:buckyroberts    | 项目源码 | 文件源码
def validate_password(password):
        """
        Validate password
        """

        validate_password(password)
        return password
项目:Vataxia    作者:buckyroberts    | 项目源码 | 文件源码
def validate_password(password):
        """
        Validate password
        """

        validate_password(password)
        return password
项目:grauth    作者:devpixelwolf    | 项目源码 | 文件源码
def validate(self, attrs):
        try:
            validators.validate_password(attrs['password'])
        except exceptions.ValidationError as e:
            raise serializers.ValidationError({'password': ['Senha inválida']})
        return attrs
项目:grauth    作者:devpixelwolf    | 项目源码 | 文件源码
def validate(self, attrs):
        if attrs['new_password'] != attrs['new_password2']:
            raise serializers.ValidationError({'password': ['A confirmação de senha e a senha são diferentes.']})
        try:
            validators.validate_password(attrs['new_password'])
        except exceptions.ValidationError as e:
            raise serializers.ValidationError({'password': ['Senha inválida']})
        return attrs
项目:grauth    作者:devpixelwolf    | 项目源码 | 文件源码
def validate(self, attrs):
        if attrs['new_password'] != attrs['new_password2']:
            raise serializers.ValidationError({'password': ['A confirmação de senha e a senha são diferentes.']})
        try:
            validators.validate_password(attrs['new_password'])
        except exceptions.ValidationError as e:
            raise serializers.ValidationError({'password': ['Senha inválida']})
        return attrs