WebMatrix WebSecurity PasswordSalt
我正在使用WebMatrix,并建立了一个基于“StarterSite”的网站。 在这个初学者网站中,您将获得一个很好的基本布局 – 包括注册,登录,忘记密码页等…
我注意到在数据库中“webpages_Membership”表有一个名为“PasswordSalt”的列。 创建一些新用户帐户后,此列始终为空。 所以我假设没有使用密码盐(甚至不是默认密码)。
显然这不是最佳实践,但我似乎找不到任何文档告诉我如何设置或管理密码盐。
如何使用WebSecurity Helper设置密码salt?
上面的答案给人的印象是,使用WebSecurity
SimpleMembershipProvider
时没有应用WebSecurity
。
事实并非如此。 实际上,未使用数据库salt字段,但这并不表示在对密码进行散列时不会生成salt 。
在WebSecurity
的SimpleMembershipProvider
了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版本,盐function/列未使用。
如果打开Web页面源,您将看到db类中包含类似的引用
INSERT INTO [" + MembershipTableName + "] (UserId, [Password], PasswordSalt
…
VALUES (uid, hashedPassword,String.Empty /* salt column is unused */
缩短了重点
有绝对的方法来覆盖和实现这种行为,首先是:
- 覆盖System.WebData.SimpleMembershipProvider.CreateAccount()
要么
- 使用System.WebData.SimpleMembershipProvider.CreateAccountWithPasswordSalt()进行扩展
除非你提出要求,否则不打算详细说明,因为你对WebMatrix和模板的使用表明你可能不想为这个项目重写你自己的C#/ ASP代码。