MembershipUser.ChangePassword始终返回false

时间:2014-04-01 17:00:42

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

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

在数据库中,与应用程序名称关联的ApplicationID是正确的,我的用户在Memberships和Users表中都附加了ApplicationID。到目前为止,User不是null,所有数据在对象中都是准确的。我在这里完全失去了,任何帮助都会非常感激,因为没有其他消息来源能够帮助我。

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

1 个答案:

答案 0 :(得分:1)

原来该公司内的其他人使用相同的DEV数据库来支持内部OpenID提供商。在开发此OpenID提供程序期间,数据被更改导致奇怪的行为。值得庆幸的是,我刚刚注意到一些数据发生了变化并询问了其他组的一些问题,使我免于浪费时间..

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

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