public PasswordResetResponse ResetPassword(string passHash, string resetToken) { try { PasswordReset reset = PasswordReset.OneWhere(c => c.Token == resetToken, Database); if (reset == null) { throw new InvalidTokenException(); } Instant timeOfRequest = new Instant(reset.DateTime.Value); Instant now = new Instant(); if (now.DiffInMinutes(timeOfRequest) > reset.ExpiresInMinutes.Value) { throw new InvalidTokenException(); } Password.Set(reset.UserOfUserId, passHash, Database); FireEvent(ResetPasswordSucceeded); return(GetSuccess <PasswordResetResponse>(true, "Password was successfully reset")); } catch (Exception ex) { LastException = ex; FireEvent(ResetPasswordFailed); return(GetFailure <PasswordResetResponse>(ex)); } }
public override int GetUserIdFromPasswordResetToken(string token) { PasswordReset reset = PasswordReset.OneWhere(c => c.Token == token); if (reset == null) { throw new InvalidOperationException("Specified token was not found ({0})"._Format(token)); } return(Convert.ToInt32(reset.UserId)); }
public override bool ResetPasswordWithToken(string token, string newPassword) { PasswordReset reset = PasswordReset.OneWhere(c => c.Token == token); if (reset == null) { return(false); } reset.WasReset = true; Password password = Password.OneWhere(c => c.UserId == reset.UserId); password.Value = newPassword; password.Save(); reset.Save(); return(true); }