Python django.conf.settings.AUTH_PASSWORD_VALIDATORS Examples

The following are 10 code examples of django.conf.settings.AUTH_PASSWORD_VALIDATORS(). 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 also want to check out all available functions/classes of the module django.conf.settings , or try the search function .
Example #1
Source File: password_validation.py    From bioforum with MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example #2
Source File: password_validation.py    From bioforum with 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
Source File: utils.py    From django-zxcvbn-password with 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
Source File: password_validation.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example #5
Source File: password_validation.py    From Hands-On-Application-Development-with-PyCharm with 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
Source File: password_validation.py    From openhgsenti with 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
Source File: password_validation.py    From openhgsenti with 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
Source File: password_validation.py    From python2017 with MIT License 5 votes vote down vote up
def get_default_password_validators():
    return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) 
Example #9
Source File: password_validation.py    From python2017 with 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
Source File: views.py    From django-rest-passwordreset with 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'})