私はSHA256を使用してパスワードをハッシュしました。私は毎回ランダムな塩生成器を生成しましたが、毎回ランダムな塩を生成し、これをパスワードに加えて暗号化してデータベースに格納します。今私はユーザーを認証しようとしていますが、私はどのようにそれを行うかわかりません。ここで私はやっているものです:asp.netを使用してMysqlでSHA256を使用するユーザーを認証します
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);
}
私は正常に保存することができますが、今どのように私はユーザーを認証することができますか? ありがとうございました... !!! :)
SHA256は、これに使用する間違った機能です。 [私たちのパスワードハッシングには服がありません](https://www.troyhunt.com/our-password-hashing-has-no-clothes/)を参照してください。トップ10の開発者の暗号ミスのリストにある[number 4](https://littlemaninmyhead.wordpress.com/2017/04/22/top-10-developer-crypto-mistakes/)も参照してください。 – TheGreatContini