当前位置: 首页>>代码示例>>Python>>正文


Python password_validation.validate_password方法代码示例

本文整理汇总了Python中django.contrib.auth.password_validation.validate_password方法的典型用法代码示例。如果您正苦于以下问题:Python password_validation.validate_password方法的具体用法?Python password_validation.validate_password怎么用?Python password_validation.validate_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.password_validation的用法示例。


在下文中一共展示了password_validation.validate_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        token = serializer.validated_data["token"]
        password = serializer.validated_data["password"]

        password_validation.validate_password(password)
        email = PasswordReset.validate_reset_token(token)

        try:
            user = User.objects.get(email__iexact=email)
        except User.DoesNotExist:
            raise ValidationError({"email": "User with that email does not exist"})

        user.set_password(password)
        user.save()
        return Response(DetailedUserSerializer(user).data, status=status.HTTP_200_OK) 
开发者ID:webkom,项目名称:lego,代码行数:20,代码来源:password_reset.py

示例2: validate_new_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_new_password(self, password):
        user = self.context['request'].user
        validate_password(password, user=user)

        username = user.username
        if len(username) and username.casefold() in password.casefold():
            raise serializers.ValidationError(
                _("The password is too similar to the username."))

        phone = user.phone
        if phone and phone_validator(phone):
            phone = str(parse_phone(phone).national_number)
            if phone in password:
                raise serializers.ValidationError(
                    _("Passwords cannot contain your phone."))

        return password 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:19,代码来源:serializers.py

示例3: validate_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_password(self, password):
        user = self.context['request'].user
        validate_password(password, user=user)
        return password 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:6,代码来源:change_password.py

示例4: post

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def post(self, request):
        messages = {"invalid_password": None, "password_validations": None, "success": None, "other": None, "mismatched": None}
        try:
            user = request.user
            old_password = request.POST.get("old_password")
            new_password = request.POST.get("new_password")
            new_password2 = request.POST.get("new_password2")
            if user.check_password(old_password) == False:
                messages["invalid_password"] = _("Invalid password")
            if new_password != new_password2:
                messages["mismatched"] = _("New password and confirmation must match")
            try:
                validation.validate_password(new_password, user)
            except ValidationError as val_err:
                messages["password_validations"] = val_err.messages

            if messages["invalid_password"] is None and messages["password_validations"] is None and messages["mismatched"] is None:
                user.set_password(new_password)
                user.save()
                authenticated_user = authenticate(username=user.username, password=new_password)
                login(request, authenticated_user)
                messages["success"] = _("Password successfully updated")

        except Exception as err:
            messages["other"] = err

        return JSONResponse(messages) 
开发者ID:archesproject,项目名称:arches,代码行数:29,代码来源:auth.py

示例5: validate_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_password(self, value):
        if value is not None:
            validate_password(value)
        return value 
开发者ID:desec-io,项目名称:desec-stack,代码行数:6,代码来源:serializers.py

示例6: validate

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate(self, data):
        """Verify passwords match."""
        passwd = data['password']
        passwd_conf = data['password_confirmation']
        if passwd != passwd_conf:
            raise serializers.ValidationError("Passwords don't match.")
        password_validation.validate_password(passwd)
        return data 
开发者ID:pablotrinidad,项目名称:cride-platzi,代码行数:10,代码来源:users.py

示例7: test_change_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def test_change_password(self) -> None:
        now = timezone_now()
        user = self.example_user('hamlet')
        password = 'test1'
        do_change_password(user, password)
        self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_PASSWORD_CHANGED,
                                                      event_time__gte=now).count(), 1)
        self.assertIsNone(validate_password(password, user)) 
开发者ID:zulip,项目名称:zulip,代码行数:10,代码来源:test_audit_log.py

示例8: validate_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_password(self, value):
        user = self.context["request"].user
        if user.has_usable_password() and not user.check_password(value):
            raise serializers.ValidationError(self.error_messages["invalid_password"])
        return value 
开发者ID:webkom,项目名称:lego,代码行数:7,代码来源:password_change.py

示例9: validate_new_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_new_password(self, password):
        if password:
            password_validation.validate_password(password)
        return password 
开发者ID:webkom,项目名称:lego,代码行数:6,代码来源:password_change.py

示例10: validate_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_password(self, password):
        password_validation.validate_password(password)
        return password 
开发者ID:webkom,项目名称:lego,代码行数:5,代码来源:registration.py

示例11: clean_password2

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def clean_password2(self):
        # Check that the two password entries match
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match")
        #self.instance.username = self.cleaned_data.get('email')
        #password_validation.validate_password(self.cleaned_data.get['password2'],self.instance)
        return password2 
开发者ID:cc0411,项目名称:devops,代码行数:11,代码来源:admin.py

示例12: validate_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_password(self, password):
        validate_password(password)

        errors = []
        email = self.initial_data.get('email')
        if email:
            email = email.split('@')
            if email[0].casefold() in password.casefold():
                errors.append(_("Passwords cannot contain your email."))

        username = self.initial_data.get('username')
        if len(username) and username.casefold() in password.casefold():
            errors.append(
                _("The password is too similar to the username."))

        phone = self.initial_data.get('phone')
        if phone:
            if phone_validator(phone):
                try:
                    phone = str(parse_phone(phone).national_number)
                    if phone in password:
                        errors.append(
                            _("Passwords cannot contain your phone."))
                except NumberParseException:
                    pass
        if errors:
            raise serializers.ValidationError(errors)

        return password 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:31,代码来源:serializers.py

示例13: __call__

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def __call__(self, value):
        """Call method, run django's validate_password method."""
        return validate_password(value) 
开发者ID:pawamoy,项目名称:django-zxcvbn-password,代码行数:5,代码来源:fields.py

示例14: create

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def create(self, validated_data):
        user_data = validated_data.pop('user')

        errors = {}
        if 'username' not in user_data:
            errors['username'] = ['This field is required.']

        if 'password' not in user_data:
            errors['password'] = ['This field is required.']

        if len(errors) > 0:
            raise serializers.ValidationError(errors)

        if 'timezone' not in validated_data:
            validated_data['timezone'] = 'UTC'

        if validated_data['timezone'] not in pytz.all_timezones:
            raise serializers.ValidationError({'timezone': ['Not a valid choice.']})

        password = user_data.pop('password')
        try:
            password_validation.validate_password(password=password, user=User)
        except exceptions.ValidationError as e:
            raise serializers.ValidationError({'password': [e.message]})

        user = User.objects.create(**user_data)
        user.set_password(password)
        user.save()

        return SciriusUser.objects.create(user=user, **validated_data) 
开发者ID:StamusNetworks,项目名称:scirius,代码行数:32,代码来源:rest_api.py

示例15: validate_new_password

# 需要导入模块: from django.contrib.auth import password_validation [as 别名]
# 或者: from django.contrib.auth.password_validation import validate_password [as 别名]
def validate_new_password(self, password):
        try:
            password_validation.validate_password(password=password, user=User)
        except exceptions.ValidationError as e:
            raise serializers.ValidationError({'password': [unicode(e)]})
        return password 
开发者ID:StamusNetworks,项目名称:scirius,代码行数:8,代码来源:rest_api.py


注:本文中的django.contrib.auth.password_validation.validate_password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。