Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying frequency lists in ZXCVBNValidator options #95

Merged
merged 3 commits into from
Dec 11, 2019

Conversation

ramonakira
Copy link
Contributor

@ramonakira ramonakira commented Dec 11, 2019

This PR allows specifying frequency_lists in the ZXCVBNValidator options by adding a dict in the following form:

    {
        'NAME': 'pages.validators.CustomZXCVBNValidator',
        'OPTIONS': {
            'min_score': 3,
            'frequency_lists': {
                'dutch': dutch_words,
            }
        }
    }

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just one thing to change 🙂

Could you also add usage example documentation to the README?

src/zxcvbn_password/validators.py Outdated Show resolved Hide resolved
@pawamoy
Copy link
Owner

pawamoy commented Dec 11, 2019

Perfect! Thanks 🙂 I'll try to release a new version ASAP.

@pawamoy pawamoy merged commit c6b4e34 into pawamoy:master Dec 11, 2019
@ramonakira
Copy link
Contributor Author

Thanks so much!

@pawamoy
Copy link
Owner

pawamoy commented Dec 12, 2019

I guess we could close #2? But the validation against custom dictionaries is only done server-side, right? We still don't have a way to do that client-side? I think I'm gonna close #2 and let someone reopen an issue if they need it client-side.

@pawamoy pawamoy mentioned this pull request Dec 12, 2019
@ramonakira
Copy link
Contributor Author

In my case the only thing that we do client-side is show the password strength bar. To make sure we get the same calculation in the bar as in the django's password validation we created a view that does the same call to zxcvbn as the password validation. Then we use that score as feedback in the password strength bar.

This can be as simple as:

class PasswordStrengthIndicatorView(View):

    def get(self, request, *args, **kwargs):
        add_frequency_lists({
            'dutch': dutch_words.get_ranked(),
        })

        password_strength = 0

        if request.GET.get('password'):
            password_strength = zxcvbn(request.GET.get('password'))['score']

        return HttpResponse(password_strength)

This has the advantage that the user does not need to download the (rather large) zxcvbn client-side library.

@pawamoy
Copy link
Owner

pawamoy commented Dec 16, 2019

Hmmm, interesting. I guess this should have been done this way from the beginning. I'll open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants