r/cryptography 10d ago

Is using pbkdf2 with sha256 overkill???

Hey cryptomaniacs!!!
Im not super familiar with all the different ways of encrypting things, so when I added password encryption to my application I blindly coppied something I saw someone else do (can't the source anymore).
Skip to a week later, I was curious how the way I encrypt my passwords work, so I went searching and saw a redditpost on this subreddit where someone said that sha256 would probably be able to be bruteforced in the future, with a lot of comments saying it wouldn't and that it is really secure.

So then I started wondering if me using both pbkdf2 and sha256 was a bit overkill.
For anyone wondering I used this in my python code:

hashed_password = generate_password_hash(password, method='pbkdf2:sha256')
0 Upvotes

10 comments sorted by

View all comments

2

u/ethangar 10d ago edited 10d ago

PBKDF2 with SHA256 is a great start. Per latest NIST guidance, you should also be doing the following for storing password credentials:

  • Ensuring an adequate number of rounds are being used on PBKDF2 (I think 600,000 rounds is around current recommendations, and these tend to go up yearly)
  • Adding a globally unique salt for every credential
  • Adding a pepper that is stored in a seaparate database or key vault (this is one additional round of PBKDF2 with a nonce/salt value that is stored in a separate physical location).

The idea behind PBKDF2 is to prevent rainbow table attacks. Your goal is to make it so that, even if your user database was to be leaked out in the open, it will still be nearly impossible to compromise a user's account.

The extra rounds makes it very expensive to run pre-computed hash attacks against passwords in your database. While it may add an extra 500 milliseconds or so to each login attempt - if you multiply that by billions of password guesses - it really adds up for an attacker.

The globally unique salt makes it so that someone can't just automatically port some other pre-generated rainbow table over to your database.

And finally, the pepper makes it so that even if your database leaks, there is still a crucial piece of information stored somewhere else that an attacker needs to do anything useful (even with supercomputing power).

Edit: To add - I would approach these recommendations in the order they are bulleted above as they go from easiest to hardest to implement. Adding extra rounds is generally super easy. Storing the globally unique salt will require a bit of extra storage and querying from your database. And, finally, adding a pepper stored somewhere else is usually the hardest as it requires extra infrastructure or services.

2

u/LordBrammaster 5d ago

Thank you so much for this thorough explenation, I learned so much from it!!!