當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.AUTH_PASSWORD_VALIDATORS屬性代碼示例

本文整理匯總了Python中django.conf.settings.AUTH_PASSWORD_VALIDATORS屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.AUTH_PASSWORD_VALIDATORS屬性的具體用法?Python settings.AUTH_PASSWORD_VALIDATORS怎麽用?Python settings.AUTH_PASSWORD_VALIDATORS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.AUTH_PASSWORD_VALIDATORS屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_default_password_validators

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import AUTH_PASSWORD_VALIDATORS [as 別名]
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:4,代碼來源:password_validation.py

示例2: get_password_validators

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import AUTH_PASSWORD_VALIDATORS [as 別名]
def get_password_validators(validator_config):
    validators = []
    for validator in validator_config:
        try:
            klass = import_string(validator['NAME'])
        except ImportError:
            msg = "The module in NAME could not be imported: %s. Check your AUTH_PASSWORD_VALIDATORS setting."
            raise ImproperlyConfigured(msg % validator['NAME'])
        validators.append(klass(**validator.get('OPTIONS', {})))

    return validators 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:13,代碼來源:password_validation.py

示例3: zxcvbn_min_score

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import AUTH_PASSWORD_VALIDATORS [as 別名]
def zxcvbn_min_score():
    zxcvbn_validator = None
    for validator in settings.AUTH_PASSWORD_VALIDATORS:
        if validator['NAME'] == 'zxcvbn_password.ZXCVBNValidator':
            zxcvbn_validator = validator
            break

    if zxcvbn_validator is not None:
        zxcvbn_min_score = zxcvbn_validator.get(
            'OPTIONS', {}).get('min_score', DEFAULT_MIN_SCORE)
    else:
        zxcvbn_min_score = DEFAULT_MIN_SCORE

    return int(zxcvbn_min_score) 
開發者ID:pawamoy,項目名稱:django-zxcvbn-password,代碼行數:16,代碼來源:utils.py

示例4: post

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import AUTH_PASSWORD_VALIDATORS [as 別名]
def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        password = serializer.validated_data['password']
        token = serializer.validated_data['token']

        # get token validation time
        password_reset_token_validation_time = get_password_reset_token_expiry_time()

        # find token
        reset_password_token = ResetPasswordToken.objects.filter(key=token).first()

        if reset_password_token is None:
            return Response({'status': 'notfound'}, status=status.HTTP_404_NOT_FOUND)

        # check expiry date
        expiry_date = reset_password_token.created_at + timedelta(hours=password_reset_token_validation_time)

        if timezone.now() > expiry_date:
            # delete expired token
            reset_password_token.delete()
            return Response({'status': 'expired'}, status=status.HTTP_404_NOT_FOUND)

        # change users password (if we got to this code it means that the user is_active)
        if reset_password_token.user.eligible_for_reset():
            pre_password_reset.send(sender=self.__class__, user=reset_password_token.user)
            try:
                # validate the password against existing validators
                validate_password(
                    password,
                    user=reset_password_token.user,
                    password_validators=get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
                )
            except ValidationError as e:
                # raise a validation error for the serializer
                raise exceptions.ValidationError({
                    'password': e.messages
                })

            reset_password_token.user.set_password(password)
            reset_password_token.user.save()
            post_password_reset.send(sender=self.__class__, user=reset_password_token.user)

        # Delete all password reset tokens for this user
        ResetPasswordToken.objects.filter(user=reset_password_token.user).delete()

        return Response({'status': 'OK'}) 
開發者ID:anexia-it,項目名稱:django-rest-passwordreset,代碼行數:49,代碼來源:views.py


注:本文中的django.conf.settings.AUTH_PASSWORD_VALIDATORS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。