Pr0gramer icon

PASSWORD HASH SALT

Pr0gramer | PRO | 09/29/18 07:29:31 AM UTC | 0 ⭐ | 315 👁️ | Never ⏰ | []
Java |

680 B

|

None

|

0 👍

/

0 👎

Does salt need to be random to secure a password hash?
private static byte[] HashPassword(string password)
{
   using (var deriveBytes = new Rfc2898DeriveBytes(password, 10))
   {
      byte[] salt = deriveBytes.Salt;
      byte[] key  = deriveBytes.GetBytes(20);
 
      return salt.Concat(key).ToArray();  //Return Salt+Key
   }
}
    
var salt = //1st  10 bytes stored in the DB
var key  = //Next 20 bytes stored in the DB 
using (var deriveBytes = new Rfc2898DeriveBytes(password, salt))
{
   byte[] newKey = deriveBytes.GetBytes(20);
 
   if (newKey.SequenceEqual(key) == false)  //Check if keys match
   {
      return "No Match";
   }
   else { return "Passwords match"; }

Comments