簡體   English   中英

WebMatrix WebSecurity PasswordSalt

[英]WebMatrix WebSecurity PasswordSalt

我正在使用WebMatrix,並建立了一個基於“StarterSite”的網站。 在這個初學者網站,你會得到一個很好的基本布局 - 包括注冊,登錄,忘記密碼頁等...

我注意到在數據庫中“webpages_Membership”表有一個名為“PasswordSalt”的列。 創建一些新用戶帳戶后,此列始終為空。 所以我假設沒有使用密碼鹽(甚至不是默認密碼)。

顯然這不是最佳實踐,但我似乎無法找到任何文檔告訴我如何設置或管理密碼鹽。

如何使用WebSecurity Helper設置密碼salt?

上面的答案給人的印象是,使用WebSecurity SimpleMembershipProvider時沒有應用WebSecurity

事實並非如此。 實際上,未使用數據庫salt字段,但這並不表示在對密碼進行散列時不會生成salt

WebSecuritySimpleMembershipProvider了PBKDF2算法,隨機鹽由StaticRandomNumberGenerator生成並存儲在帶有哈希的密碼字段中:

byte[] outputBytes = new byte[1 + SALT_SIZE + PBKDF2_SUBKEY_LENGTH];
Buffer.BlockCopy(salt, 0, outputBytes, 1, SALT_SIZE); 
Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SALT_SIZE, PBKDF2_SUBKEY_LENGTH);
return Convert.ToBase64String(outputBytes);

從WebMatrix / ASP.NET網頁的RTM版本開始,salt功能/列未使用。

如果打開Web頁面源代碼,您將看到db類中包含類似的引用

INSERT INTO [" + MembershipTableName + "] (UserId, [Password], PasswordSalt

...

VALUES (uid, hashedPassword,String.Empty /* salt column is unused */

縮短了重點

有絕對的方法來覆蓋和實現這種行為,首先是:

  • override System.WebData.SimpleMembershipProvider.CreateAccount()

要么

  • 使用System.WebData.SimpleMembershipProvider.CreateAccountWithPasswordSalt()進行擴展

除非你提出要求,否則不打算詳細說明,因為你使用WebMatrix和模板表明你可能不想為這個項目重寫你自己的C#/ ASP代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM