Python django.conf.settings.AUTH_PASSWORD_VALIDATORS Examples

The following are 10 code examples for showing how to use django.conf.settings.AUTH_PASSWORD_VALIDATORS(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: bioforum   Author: reBiocoder   File: password_validation.py    License: MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example 2
Project: bioforum   Author: reBiocoder   File: password_validation.py    License: MIT License 5 votes vote down vote up
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 
Example 3
Project: django-zxcvbn-password   Author: pawamoy   File: utils.py    License: ISC License 5 votes vote down vote up
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) 
Example 4
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: password_validation.py    License: MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example 5
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: password_validation.py    License: MIT License 5 votes vote down vote up
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 
Example 6
Project: openhgsenti   Author: drexly   File: password_validation.py    License: Apache License 2.0 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example 7
Project: openhgsenti   Author: drexly   File: password_validation.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 8
Project: python2017   Author: bpgc-cte   File: password_validation.py    License: MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example 9
Project: python2017   Author: bpgc-cte   File: password_validation.py    License: MIT License 5 votes vote down vote up
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 
Example 10
Project: django-rest-passwordreset   Author: anexia-it   File: views.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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'})