I use the system that the previous developer wrote about. The system has an administrator approving the user account, and when they do this, the system uses the following method to hash the password and store it in the database. It sends an unmanaged password to the user. When a user logs on to the system, he uses the same method for the hash that the user enters and compares it with the database value. We encountered them several times when the record in the database does not match the input serum that they should use. Thus, it seems that the method does not always hash the value of the same thing. Does anyone know if this hashing method is reliable and how to make it reliable? Thank.
private string HashPassword(string password)
{
string hashedPassword = string.Empty;
byte[] plainTextBytes = Encoding.UTF8.GetBytes(password);
byte[] plainTextWithSaltBytes =
new byte[plainTextBytes.Length + SALT.Length];
for(int i = 0; i < plainTextBytes.Length; i++)
plainTextWithSaltBytes[i] = plainTextBytes[i];
for(int i = 0; i < SALT.Length; i++)
plainTextWithSaltBytes[plainTextBytes.Length + i] = SALT[i];
HashAlgorithm hash = new SHA256Managed();
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);
byte[] hashWithSaltBytes = new byte[hashBytes.Length +
SALT.Length];
for(int i = 0; i < hashBytes.Length; i++)
hashWithSaltBytes[i] = hashBytes[i];
for(int i = 0; i < SALT.Length; i++)
hashWithSaltBytes[hashBytes.Length + i] = SALT[i];
hashedPassword = Convert.ToBase64String(hashWithSaltBytes);
return hashedPassword;
}