0
我與此problem類似,但我使用ASP身份驗證和基於令牌的身份驗證。使用ASP標識重置密碼後無法使用新密碼登錄
後復位或設置新密碼,PasswordHash在我的用戶的表更新,但用戶不能使用新密碼登錄,直到重新啓動其中的Web-API託管服務。
在我的AccountController:
// POST api/Account/ChangePassword
[Route("ChangePassword")]
public async Task<IHttpActionResult> ChangePassword(ChangePasswordBindingModel model)
{
if (!this.ModelState.IsValid)
{
return this.BadRequest(this.ModelState);
}
IdentityResult result = await this.UserManager.ChangePasswordAsync(this.User.Identity.GetUserId<int>(), model.OldPassword,
model.NewPassword);
IHttpActionResult errorResult = this.GetErrorResult(result);
if (errorResult != null)
{
return errorResult;
}
return this.Ok();
}
[AllowAnonymous]
[HttpPost]
public async Task<IHttpActionResult> ResetPassword(ResetPasswordBindingModel model)
{
if (model.UserId<= 0 || model.Code == null)
{
return this.BadRequest();
}
IdentityResult result;
try
{
result = await this.UserManager.ResetPasswordAsync(model.UserId, model.Code, model.Password);
}
catch (InvalidOperationException exception)
{
return this.InternalServerError(exception);
}
IHttpActionResult errorResult = this.GetErrorResult(result);
if (errorResult != null)
{
return errorResult;
}
return this.Ok();
}
在ApplicationOAuthProvider:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
try
{
var user = await this.userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
this.logger.Info("Invalid grant for {0}", context.UserName);
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
var oAuthIdentity =
await this.userManager.CreateIdentityAsync(user, context.Options.AuthenticationType);
var cookiesIdentity =
await this.userManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType);
var properties = CreateProperties(user.UserName);
var ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
this.logger.Info("User '{0}' is signed in.", user.UserName);
}
catch (Exception ex)
{
this.logger.Error(ex.Message, ex);
throw;
}
誰能幫助我?謝謝。