public ActionResult emailotp(OTPmailValidater oTP) { string sessionOTP = Session["msgotp"].ToString(); if (oTP.emailotpstring == sessionOTP) { FormsAuthentication.SetAuthCookie(User.Identity.Name, false); return(RedirectToAction("Setpassword", "Account")); } ViewBag.Message = "Error"; return(View(oTP)); }
public ActionResult emailotp() { int otpValue = new Random().Next(100000, 999999); var status = ""; OTPmailValidater ob = new OTPmailValidater(); try { Session["msgotp"] = otpValue; //string msg = "your otp from abc.com is " + otpValue; paresetEntities db = new paresetEntities(); var uemail = db.Userinfoes.FirstOrDefault(u => u.username == User.Identity.Name); string recipient = uemail.email.ToString(); string masked = "XXXXXXXX" + recipient.Substring(recipient.Length - 10); string emailfrom = System.Configuration.ConfigurationManager.AppSettings["fromemail"].ToString(); string passwordmail = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(); MailMessage msg = new MailMessage(); msg.From = new MailAddress(emailfrom); msg.To.Add(recipient); msg.Subject = "Random Password for your Account"; msg.Body = "Your Random password is:" + otpValue; msg.IsBodyHtml = true; SmtpClient smt = new SmtpClient(); smt.Host = "smtp.zoho.com"; System.Net.NetworkCredential ntwd = new System.Net.NetworkCredential(); ntwd.UserName = emailfrom; //Your Email ID ntwd.Password = passwordmail; // Your Password smt.UseDefaultCredentials = true; smt.Credentials = ntwd; smt.Port = 587; smt.EnableSsl = true; smt.Send(msg); ob.msakemaillable = masked; ob.username = User.Identity.Name.ToString(); return(View(ob)); } catch (Exception e) { ob.msakemaillable = "Error"; ob.username = User.Identity.Name.ToString(); return(View(ob)); } }