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

Cannot call hash_password with one argument #78

Closed
Vayel opened this issue Jan 1, 2019 · 1 comment
Closed

Cannot call hash_password with one argument #78

Vayel opened this issue Jan 1, 2019 · 1 comment

Comments

@Vayel
Copy link

Vayel commented Jan 1, 2019

The documentation gives this example:

@auth.hash_password
def hash_pw(password):
    return md5(password).hexdigest()

But this code raises two exceptions:

TypeError: hash_pw() takes 1 positional argument but 2 were given

After the above is fixed:

...
    return hashlib.sha512(password).hexdigest()
TypeError: Unicode-objects must be encoded before hashing

The following code works:

@auth.hash_password
def hash_pw(username, password):
    return hashlib.sha512(password.encode("utf8")).hexdigest()

I am using Python 3.7 and Flask is served through gevent.

Thanks!

@miguelgrinberg
Copy link
Owner

Yes, I have updated the docs with the correct usage. Thanks!

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

No branches or pull requests

2 participants