Where to store salt for salt and how to get it?

I am responsible for the authentication in our .Net MVC 4 web application, and I have encountered the problem of hashing, storing and authenticating passwords.

Currently, Plan uses 2 salts, 1 dynamic (per user) and 1 static (persistent web application) and a strong hash function.

Given a simple user table containing a username and password:

  • Do I save user salt in a user table column?

My concern is that, having done this, I will need to get the user from the database in the memory of the web application with only his username. Is there some kind of attack where this can be problematic? Ideally, I would like it to be a single request check per step / one.

Am I too worried? Is there an alternative to the Per User salt where I can still perform one-step authentication?

+6
source share
2 answers

A salt can be stored with a password hash, so you can create a salt for each password instead of each user. It is common practice for password hash functions (a slow key output function such as BCrypt or PBKDF2) to return the solar text as part of the password hash, which means that you can store the salt and hash together in the same database field.

To verify the entered password, you first need to look for the hash password (using the username or email address), and then the function can extract the used salt from the stored password and use it to compare hashes. This should actually answer your question, databases usually do not have the corresponding functions for hash passwords, so you cannot perform validation in an SQL query, the verification will be performed in code.

The second salt is actually called pepper, the best way to add this secret on the server side is to encrypt an already hashed password with this secret. Unlike a hash, it will be two-way encryption, which allows you to exchange a key if it is ever needed.

+3
source

You do not need an external library for this. The framework has its own built-in implementation of PBKDF2. I prefer to store salt in a separate field in the database, but this is just a matter of taste, I think. I wrote my thoughts on hashing passwords here

+1
source

Source: https://habr.com/ru/post/949025/


All Articles