ForgotPassword
How to Implement Forgotten Password that is going to sent the "Url "To reset password by Email
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bandisiwe SpivaPosted Jul 30, 2015, 5:17 AM
The following code shows the
POST ForgotPasswordmethod.Vipan SharmaPosted Jul 29, 2015, 7:20 AM
Rajeesh MenothPosted Jul 29, 2015, 6:09 AM
Simphiwe SibiyaPosted Jul 29, 2015, 5:29 AM
HI, THIS GOES INTO YOUR CONTROLLER
ForgotPassword(ForgotViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
// Don't reveal that the user does not exist or is not confirmed
return View("ForgotPasswordConfirmation");
}
var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account",
new { UserId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Reset Password",
"Please reset your password by clicking here: link");
return View("ForgotPasswordConfirmation");
}
return View(model);
}
THIS IS THE VIEW
/// Forgot View
h2>ForgotPassword
@using (Html.BeginForm("ForgotPassword", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
Enter your email.
@Html.ValidationSummary("", new { @class = "text-danger" })
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
}