Cannot login with new password after resetting using SqlMembership Provider

瘦欲@ 提交于 2019-12-08 12:25:11

问题


After resetting the password using SqlMembership provider.I am unable to login with the new password. Below is the line of code used to reset the password for dbo.aspnet_Membership table. Password is encrypted . Everytime I reset the password a new encrypted value is stored inside the table. But unable to login.

My webconfig setting:

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider"    connectionStringName="xxxx" applicationName="xxxx" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" />
  </providers>
</membership>

C# code:

Membership user= Membership.GetUser(txtUser.Text);
user.ResetPassword(txtNewPassword.Text);

Can anyone help me with this.Why I can't still login with the new password?


回答1:


ResetPassword is not actually the function you should be using for setting a new user password. See:

http://msdn.microsoft.com/en-us/library/d94bdzz2(v=vs.110).aspx

ResetPassword is for generating a new random password (imagine a forgot my password link). The constructor you're using (string) isn't for the new password, it's for answering a secret question if applicable.

The method you should actually be using is ChangePassword. See:

http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.changepassword(v=vs.110).aspx

You'd consume that similar to:

Membership user= Membership.GetUser(txtUser.Text);
user.ChangePassword(oldPasswordString, txtNewPassword.Text);


来源:https://stackoverflow.com/questions/26675391/cannot-login-with-new-password-after-resetting-using-sqlmembership-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!