public ActionResult ForgotPassword(string UserName) { if (ModelState.IsValid) { if (WebSecurity.UserExists(UserName)) { string To = UserName, UserID, Password, SMTPPort, Host; string token = WebSecurity.GeneratePasswordResetToken(UserName); if (token == null) { // If user does not exist or is not confirmed. return(View("Index")); } else { //Create URL with above token var lnkHref = "<a href='" + Url.Action("ResetPassword", "Account", new { email = UserName, code = token }, "http") + "'>Reset Password</a>"; //HTML Template for Send email string subject = "Your changed password"; string body = "<b>Please find the Password Reset Link. </b><br/>" + lnkHref; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } } } return(View()); }
public ActionResult ForgotPassword(string EmailAddress) //can pass the viewmodel with property called emailID { if (ModelState.IsValid) { if (WebMatrix.WebData.WebSecurity.UserExists(EmailAddress)) { //string str = abc, dfg; string To = EmailAddress, UserId, UserPassword, SMTPPort, Host; string token = WebSecurity.GeneratePasswordResetToken(EmailAddress, 1440); if (token == null) { return(View(""));// if doesnt match } else { var lnkHref = "<a href='" + Url.Action("ResetPassword", "Account", new { email = EmailAddress, code = token }, "http") + "'>Reset Password</a>"; // creats url with above token // html template for send email string subject = "Your Changed password"; string body = "<b> Please find the password reset link. </b><br/>" + lnkHref; // get and set the appSettings using configuration manager. EmailManager.AppSettings(out UserId, out UserPassword, out SMTPPort, out Host); //call send email methods EmailManager.SendEmail(UserId, subject, body, UserId, To, UserPassword, SMTPPort, Host); } } } //AccessManagementServices.AccessManagementServicesClient clientaccess = new AccessManagementServices.AccessManagementServicesClient(); //int UId = clientaccess.GetPasswordData(management); //if(UId!= 0) //{ // return View(""); //} //else //{ // return View(""); //} return(View()); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string 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 <a href=\"" + callbackUrl + "\">here</a>"); string To = model.Email, UserID, Password, SMTPPort, Host; EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); string subject = "Your changed password"; string body = "<b>Please find the Password Reset Link below. </b><br/><br/>" + "<a href=\"" + callbackUrl + "\">Click here</a>"; EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form return(View(model)); }