WebMatrix WebSecurity 密码盐

发布于 2024-10-19 03:12:12 字数 279 浏览 9 评论 0原文

我正在使用 WebMatrix 并建立了一个基于“StarterSite”的网站。在这个入门网站中,您会得到一个很好的基本布局 - 包括注册、登录、忘记密码页面等...

我注意到在数据库中,“webpages_Membership”表有一列名为“PasswordSalt”。创建几个新的用户帐户后,此列始终保持空白。所以我假设没有使用密码盐(甚至不是默认的)。

显然这不是最佳实践,但是我似乎找不到任何文档告诉我如何设置或管理密码盐。

如何使用 WebSecurity Helper 设置密码盐?

I am using WebMatrix and have built a website based on the "StarterSite". In this starter site you get a nice basic layout - including registration, login, forgot password pages etc...

I've noticed that in the database that the "webpages_Membership" table has a column named "PasswordSalt". After creating a few new user accounts, this column always remains blank. So I'm assuming that no password salt (not even a default one) is in use.

Obviously this is not the best practice, however I cannot seem to find any documentation that tells me how to set or manage the password salt.

How can I set the password salt with the WebSecurity Helper?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坦然微笑 2024-10-26 03:12:12

上面的答案给人的印象是,使用 WebSecurity SimpleMembershipProvider 时没有应用加盐。

那不是真的。实际上,没有使用数据库盐字段,但这并不表明在对密码进行哈希处理时没有生成

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);

The above answer gives the impression that there is no salting applied when using WebSecurity SimpleMembershipProvider.

That is not true. Indeed the database salt field is not used, however this does not indicate that there is no salt generated when hashing the password.

In WebSecuritys SimpleMembershipProvider the PBKDF2 algo is used, the random salt is generated by the StaticRandomNumberGenerator and stored in the password field with the hash:

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);
挽手叙旧 2024-10-26 03:12:12

从 WebMatrix/ASP.NET 网页的 RTM 版本开始,salt 功能/列未使用。

如果您打开网页源代码,您将看到数据库类散布着诸如

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

...

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

为了强调而缩短的引用,

肯定有方法可以覆盖和实现此行为,首先是

  • : WebData.SimpleMembershipProvider.CreateAccount()

  • 使用 System.WebData.SimpleMembershipProvider.CreateAccountWithPasswordSalt() 进行扩展,

除非您要求,否则不会详细介绍,因为您对 WebMatrix 和模板的使用表明您可能不想乱重写该项目需要大量您自己的 C#/ASP 代码。

As of the RTM release of WebMatrix/ASP.NET Web Pages, the salt feature/column is unused.

If you open up the Web Pages source, you'll see the db classes littered with references like

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

...

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

shortened for emphasis

There are definately ways to override and implement this behavior, first being:

  • override System.WebData.SimpleMembershipProvider.CreateAccount()

or

  • extend with System.WebData.SimpleMembershipProvider.CreateAccountWithPasswordSalt()

not going to go into detail there though unless you request, as your usage of WebMatrix and a template suggests you probably don't wanna mess with rewriting a ton of your own C#/ASP code for this project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文