@{
Layout = "~/Shared/Layouts/_Layout.cshtml";
Page.Title = "Reset Password";
var resetToken = Request["resetToken"] ?? "";
var message = "";
var newPassword1 = "";
var newPassword2 = "";
if(IsPost) {
newPassword1 = Request["newPassword1"];
newPassword2 = Request["newPassword2"];
// Validation
if (newPassword1.IsEmpty()) {
ModelState.AddError("newPassword1", "Required.");
}
if (newPassword2.IsEmpty()) {
ModelState.AddError("newPassword2", "Required.");
}
if(newPassword1 != newPassword2)
{
ModelState.AddError("newPassword1", "The passwords do not match.");
}
// Attempt password reset
if(ModelState.IsValid)
{
if (WebSecurity.ResetPassword(resetToken, newPassword1))
{
message = "Password changed successfully.";
}
else
{
message = "Unable to change password.";
}
}
}
}

<h2>Reset your password</h2>
@if (!message.IsEmpty()) {
    <p>@message</p>
}
else
{
<form action="PasswordReset" method="post" class="accountForm">
@Html.Hidden("resetToken", resetToken)
<p>
@Html.Label("New Password: ", "newPassword1")<br />
@Html.Password("newPassword1", newPassword1)
@Html.ValidationMessage("newPassword1")
</p>
<p>
@Html.Label("Confirm New Password: ", "newPassword2")<br />
@Html.Password("newPassword2", newPassword2)
@Html.ValidationMessage("newPassword2")
</p>
<p>
<input type="submit" value="Reset Password" />
</p>
</form>
}
