I am quite new to cryptography and want to get my head around hashing algorithms.
I have sources the following to create a hashed version of a password, which can be stored in my database.
public static string hashPasswordGenerator(string password)
{
System.Security.Cryptography.SHA256Managed crypt = new System.Security.Cryptography.SHA256Managed();
StringBuilder hash = new StringBuilder();
byte[] cry = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
return Convert.ToBase64String(cry);
}
My example user is User1
with password Password1
, this returns a hashed version of GVE/3J2k+3KkoF62aRdUjTyQ/5TVQZ4fI2PuqJ3+4d0=
My questions are:
- Is this secure?
- Should I add a salt to this? If so can someone show me a simple example as I do not really understand how the salt it generated so that it will match the password every time?
- If someone has this hashPasswordGenerator method could they reverse engineer my password?
Thanks in advance.