Asp.net
使用 SimpleMembershipProvider 時使用鹽
可能重複:
有沒有辦法讓 simpleMembershipProvider 使用鹽?
當我創建我的 mvc4 web 項目並將預設連接設置為 sqlexpress,然後註冊時,我的使用者沒有密碼 salt
我希望它盡可能安全而不會帶來太多麻煩。
PasswordSalt 列未使用,但在創建儲存在 Password 欄位中的散列密碼時使用加鹽。如果您查看 SimpleMembershipProvider 的原始碼,您可以看到這一點:http: //aspnetwebstack.codeplex.com/SourceControl/changeset/view/3a669e7112e7#src%2fWebMatrix.WebData%2fSimpleMembershipProvider.cs
檢查 CreateUserAndAccount 方法。它使用Crypto.HashPassword方法:
/* ======================= * HASHED PASSWORD FORMATS * ======================= * * Version 0: * PBKDF2 with HMAC-SHA1, 128-bit salt, 256-bit subkey, 1000 iterations. * (See also: SDL crypto guidelines v5.1, Part III) * Format: { 0x00, salt, subkey } */ public static string HashPassword(string password) { if (password == null) { throw new ArgumentNullException("password"); } // Produce a version 0 (see comment above) password hash. byte[] salt; byte[] subkey; using (var deriveBytes = new Rfc2898DeriveBytes(password, SaltSize, PBKDF2IterCount)) { salt = deriveBytes.Salt; subkey = deriveBytes.GetBytes(PBKDF2SubkeyLength); } byte[] outputBytes = new byte[1 + SaltSize + PBKDF2SubkeyLength]; Buffer.BlockCopy(salt, 0, outputBytes, 1, SaltSize); Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SaltSize, PBKDF2SubkeyLength); return Convert.ToBase64String(outputBytes); }基本上,為了解決您的顧慮,它既安全又安全,您不必再遇到任何額外的麻煩。
