在 web.config 中为凭据指定 passwordFormat 时,如何处理解密?
如果我将应用程序设置为使用表单身份验证,并且在 web.config 中指定凭据,如下所示:
<authentication mode="Forms">
<forms loginUrl="~/LogOn" name=".ASPXAUTH" path="/" defaultUrl="~/AuthArea" timeout="2880">
<credentials passwordFormat="MD5">
<user name="user" password="user123" />
</credentials>
</forms>
</authentication>
那么,我如何在登录操作中验证凭据?
if (FormsAuthentication.Authenticate(model.UserName, model.Password)) {
我不需要使用 MD5 对用户输入的密码进行加密吗?如果是这样,你该怎么做?
谢谢。
If I setup my app to use forms authentication, and I specify the credentials in web.config like this:
<authentication mode="Forms">
<forms loginUrl="~/LogOn" name=".ASPXAUTH" path="/" defaultUrl="~/AuthArea" timeout="2880">
<credentials passwordFormat="MD5">
<user name="user" password="user123" />
</credentials>
</forms>
</authentication>
How do I then, in my LogOn Action validate the credentials?
if (FormsAuthentication.Authenticate(model.UserName, model.Password)) {
Won't I need to encrypt the user entered password using MD5? And if so, how do you do that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 FormsAuthentication.Authenticate 时不需要加密密码。不过,您在 web.config 中的密码需要使用 MD5 进行加密。这是我使用的代码:
You do not need to encrypt the password when you are using FormsAuthentication.Authenticate. Your password in the web.config will need to be encrypted in MD5 though. here is the code I use:
您必须编写(或修改)安全提供程序来加密密码并将其与存储的凭据进行比较。我给您的最大建议是从现有的安全提供程序(如 SqlServerRoleProvider)开始(它作为默认提供程序连接在所有新的 MVC/Web Forms 项目中)。
详细信息可以在这里找到:
http://msdn.microsoft.com/en-us/library/ff649314.aspx仅供
参考:M$ 提供的安全提供程序默认处理加密。这意味着您不必自定义编写它:-) 我想说从 SQL Server 成员资格提供程序示例和数据库表开始,然后从那里开始分支。
You would have to write (or modify) the Security Provider to encrypt the password and compare it against the credentials that are stored. My biggest advice to you is start from an existing security provider like the SqlServerRoleProvider (which is wired up in all the new MVC / Web Forms projects as the default provider).
Details can be found here:
http://msdn.microsoft.com/en-us/library/ff649314.aspx
FYI: The security providers that M$ provides handles encryption BY DEFAULT. This means you don't have to custom write it :-) I'd say start with a SQL Server Membership Provider example and database tables and branch out from there.