private void Send(User user) { var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6))); _verificationRepository.SendResetVerificationToken(user.UserId, emailVerficationToken); MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); try { MailAddress fromAddress = new MailAddress(_appSettings.EmailFrom); message.From = fromAddress; message.To.Add(user.Email); message.Subject = "Welcome to Web Secure"; message.IsBodyHtml = true; message.Body = SendVerificationEmail(user, emailVerficationToken); smtpClient.Host = _appSettings.Host; smtpClient.Port = Convert.ToInt32(_appSettings.Port); smtpClient.EnableSsl = true; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential(_appSettings.EmailFrom, _appSettings.Password); smtpClient.Send(message); } catch (Exception) { throw; } }
// GET: PasswordReset public async Task <ActionResult> Process(ForgotPasswordModel resetPasswordModel) { try { if (ModelState.IsValid) { var result = _verify.ValidateEmailIdExists(resetPasswordModel.EmailId); if (!result) { TempData["PasswordResetMessage"] = "In Valid EmailId"; } else { SendingEmailhelper sendingEmailhelper = new SendingEmailhelper(); var generatecode = GenerateHashSha256.ComputeSha256Hash(GenerateRandomNumbers.RandomNumbers(6)); var userId = _userMaster.GetUserIdbyEmailId(Convert.ToString(resetPasswordModel.EmailId)); var count = _verification.GetSentResetPasswordVerificationCount(userId); var sentEmailCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxResetEmailCount"]); if (count == sentEmailCount) { TempData["PasswordResetMessage"] = "You Have exceed Limit for Resetting Password"; } else { _verification.SendResetVerificationToken(userId, generatecode); TempData["PasswordResetMessage"] = "Email Sent to your Account"; await sendingEmailhelper.SendForgotPasswordVerificationEmailasync(resetPasswordModel.EmailId, generatecode, "ForgotPassword", userId.ToString()); } } } return(View(resetPasswordModel)); } catch (Exception) { throw; } }
public async Task <ActionResult> Register(UsermasterView usermaster) { try { if (ModelState.IsValid) { if (!this.IsCaptchaValid("Captcha is not valid")) { ModelState.AddModelError("", "Error: captcha is not valid."); return(View(usermaster)); } if (_iUserMaster.CheckUsernameExists(usermaster.UserName)) { ModelState.AddModelError("", "UserName already exists"); return(View(usermaster)); } if (_iUserMaster.CheckEmailIdExists(usermaster.EmailId)) { ModelState.AddModelError("", "EmailId already exists"); return(View(usermaster)); } if (_iUserMaster.CheckMobileNoExists(usermaster.MobileNo)) { TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists"; } var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster); var salt = GenerateRandomNumbers.RandomNumbers(20); var saltedpassword = GenerateHashSha512.Sha512(usermaster.Password, salt); var userId = _iUserMaster.AddUser(autoUsermaster, saltedpassword, salt, Convert.ToInt16(StatusMain.Roles.User)); if (userId != -1) { var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6))); _verification.SendRegistrationVerificationToken(userId, emailVerficationToken); SendingEmailhelper sendingEmailhelper = new SendingEmailhelper(); var name = string.Concat(usermaster.FirstName, usermaster.LastName); await sendingEmailhelper.SendVerificationEmailasync(usermaster.EmailId, name, emailVerficationToken, "Registration", Convert.ToString(userId)); TempData["MessageRegistration"] = "Thank you. Your Registration has been completed successfully."; } else { TempData["ErrorRegistration"] = "Something Went Wrong While you are registering.Please try after sometime."; } return(RedirectToAction("Register", "Registration")); } else { return(View("Register", usermaster)); } } catch { throw; } }