I have hashed the passwords using SHA256. I have generated a random salt generator which every time generates a random salt which is added up to the password, which then gets encrypted and is being stored in the database. Now I am trying to authenticate the users and I am not sure how to do that. Here is what I am doing:
public static String ByteArrayToHexString(byte[] ba)
{
System.Text.StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
{
hex.AppendFormat("{0:x2}", b);
}
return hex.ToString();
}
public String CreateSalt(int size) // Function to generate a random salt
{
var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
var buff = new byte[size];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
public String GenerateSHA256Hash(String input, String salt) // Function to add user input and randomly generated salt
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
System.Security.Cryptography.SHA256Managed sha256hashstring = new System.Security.Cryptography.SHA256Managed();
byte[] hash = sha256hashstring.ComputeHash(bytes);
return ByteArrayToHexString(hash);
}
I can store it successfully but now how can I authenticate the users? Thanks in Advance...!!! :)