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

Don't crash when logging in users with old-style password hashes #2033

Merged

Conversation

lunkwill42
Copy link
Member

Some user accounts still have old-style password hashes in the NAV account database (meaning their password has not been changed in years!).

Under Python 3, the verification of such old-style hashes will crash during the web login phase, since a string object is fed to a hashlib hash function that expects a bytes object.

Ultimately, support for old-style password hashes should be phased out. This PR will re-hash a user's password whenever an old-style password hash is found and verified.

Because:
- This would crash in hashlib under Python 3, as password is a string,
  while md5 hashes require binary data.
- This only crashes on long-living NAV installs where there may still be
  old-style password hashes on some accounts.
Because:
- Leaving old-style, unsalted md5 password hashes in the database is
  stupid and ultimately insecure.
- Active users should have their password hashes more secure.

At some point in the future, we should stop supporting old-style hashes
altogether.
@lunkwill42 lunkwill42 added this to the 5.0.1 milestone Dec 4, 2019
@lunkwill42 lunkwill42 requested a review from hmpf December 4, 2019 13:28
Copy link
Contributor

@hmpf hmpf left a comment

Choose a reason for hiding this comment

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

Seems to fix the current problem, but MD5 in (almost) 2020?

https://medium.com/@mpreziuso/password-hashing-pbkdf2-scrypt-bcrypt-and-argon2-e25aaf41598e

@hmpf
Copy link
Contributor

hmpf commented Dec 4, 2019

@lunkwill42
Copy link
Member Author

Seems to fix the current problem, but MD5 in (almost) 2020?

For verification of old hashes, yes. No new hashes are stored using md5.

@lunkwill42
Copy link
Member Author

Something like this might be the smartest way to go:

https://docs.djangoproject.com/en/2.2/topics/auth/passwords/#password-upgrading-without-requiring-a-login

So, basically, hash-in-hash? :-D

@lunkwill42 lunkwill42 merged commit 3776c05 into Uninett:5.0.x Dec 5, 2019
@lunkwill42 lunkwill42 deleted the bugfix/old-style-password-hashes branch December 5, 2019 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants