【问题标题】:MembershipUser.ChangePassword returns false at all timesMembershipUser.ChangePassword 始终返回 false
【发布时间】:2014-04-01 17:00:41
【问题描述】:

使用 System.Web.Providers.DefaultMembershipProvider 和 System.Web.Security.MembershipUser,我正在尝试更改数据库中的用户密码。出于某种原因,无论我做什么, MembershipUser.ChangePassword(old, new) 都会返回 false 且没有错误。

在数据库中,与应用程序名称关联的 ApplicationID 是正确的,并且我的用户在 Memberships 和 Users 表中都附加了该 ApplicationID。就这一点而言,用户不为空,对象中的所有数据都是准确的。我在这里完全不知所措,任何帮助将不胜感激,因为没有其他来源能够帮助我。

EDIT: 
User is not locked out, the user is active, and the password is correct. All
password requirements are being fulfilled. This is extremely frustrating since 
the MembershipUser.GetUser() finds the user and all of its associated data but 
will not change the password.

Additional Steps:
    - Tried MembershipUser.UnlockUser() just in case, no luck.
    - Tried MembershipUser.ResetPassword() then a change. This fails with the 
      error message "Value cannot be null" even though it should be able to.
    - GetSpecificVerion of the entire solution and working to when it first 
      broke. Every version worked, including my latest (Yay!), but then it
      magically stopped working again a few minutes later, no code changes
      were made at all.

Bounty added, looking for any and all possibilities that could lead to a fix...

配置文件:

----
<add name="aspnetdb" connectionString="Application Name=appname;Type System Version=SQL Server 2008;server=***,****;Initial Catalog=aspnetdb;Integrated Security=false;pwd=****;user id=****" providerName="System.Data.SqlClient" />    
----

----
<membership defaultProvider="DefaultMembershipProvider">
    <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="aspnetdb" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" passwordAttemptWindow="10" applicationName="mysite.com" />
    </providers>
</membership>
----

方法:

public ActionResult ChangePassword(ChangePasswordViewModel model)
{
    // Indicates whether changing the password was successful or not.
    Boolean passwordChanged = false;

    if (ModelState.IsValid)
    {
        // Grab the current user.
        MembershipUser user = Membership.GetUser(User.Identity.Name, true);

        if (user != null)
        {
            passwordChanged = user.ChangePassword(model.OldPassword, model.NewPassword);
        }
    }

    return Json(new { Success = passwordChanged });
}

【问题讨论】:

  • 是报错,还是代码运行正常,但是密码没变?另外,请确保用户没有被锁定...
  • 请告诉我们错误。
  • 对不起,它返回 false 没有错误。更新了问题。
  • 您是否设置了符合您的最低要求的新密码(例如 minRequiredPasswordLength=7)?否则你会得到一个虚假的回报!
  • 所有验证通过,目前只设置了 7-100 个字符的限制。将使用该信息更新问题:)

标签: c# asp.net-mvc membership-provider membershipuser


【解决方案1】:

原来公司内的其他人正在使用同一个 DEV 数据库来支持内部 OpenID 提供程序。在此 OpenID 提供程序的开发过程中,数据发生了变化,导致了奇怪的行为。谢天谢地,我恰好注意到我的一些数据变化,并向其他小组提出了一些问题,让我不再浪费时间。..

这仍然很奇怪,我能够检索用户但没有更改该用户的密码。最后,清理两个项目之间的沟通似乎已经解决了这个问题。

在共享数据库时学到了很好的一课。感谢那些试图提供帮助的人:)

【讨论】:

    猜你喜欢
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 2020-10-03
    • 2017-01-18
    相关资源
    最近更新 更多