回答

25

PasswordSalt列未使用,但在創建存儲在Password字段中的散列密碼時使用salting。如果您查看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); 
    } 

基本上能解決您的問題,這是因爲安全,因爲它需要沒有你不必去任何額外的麻煩。從documentation

+0

嗯,那爲什麼還有鹽柱呢?如果鹽列是有用的,我們可以做些什麼樣的情景? – jonprasetyo

+0

@jonprasetyo我不知道。我最好的猜測是,它是從以前的提供程序模式中引入的,並且在決定將salt與散列集成並將其存儲在一個地方時不會丟失。 –

2

報價:

在設計上,SimpleMembershipProvider類沒有實現 全方位的功能,可以在ASP.NET成員 供應商,如所使用MembershipProvider類中定義通過 所有ASP.NET成員資格提供程序。有些成員在 類中可用,因爲它們是從基類繼承而來的,但是如果您訪問它們,將會拋出 異常。

如果您的網站需要所有成員提供能力, 你可以跳過網頁的會員系統的初始化(即 是,不叫WebSecurity.InitializeDatabaseConnection())和 而是確保標準的成員資格和角色提供商已啓用 。在這種情況下,您對 SimpleMembershipProvider類進行的調用將被傳遞給標準 提供者(它被稱爲 SimpleMembershipProvider類文檔中的以前的提供者)。有關更多信息,請參閱 請參閱配置ASP.NET應用程序以使用成員身份。

PasswordSalt字段是其中的一列。如果你看一下SimpleMembershipProvider的源代碼,你會發現,PasswordSalt列被簡單地設置string.Empty

if (database.Execute("INSERT INTO [" + MembershipTableName + "] (UserId, [Password], PasswordSalt, IsConfirmed, ConfirmationToken, CreateDate, PasswordChangedDate, PasswordFailuresSinceLastSuccess) VALUES (@0, @1, @2, @3, @4, @5, @5, @6)", new object[] { num, str, string.Empty, !requireConfirmationToken, obj3, DateTime.UtcNow, num2 }) != 1) 
{ 
    throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError); 
} 

所以,如果你想使用它,你可以寫覆蓋缺省定製的會員提供一個與自己生成PasswordSalt。您可以覆蓋CreateAccount方法。

+0

達林,但密碼列確實擁有散列密碼。微軟使用哪種鹽? Mac地址? – ilans

相關問題