public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { if (_adminBLL.resettPassord(model)) { ModelState.AddModelError("", "Mail er sendt til " + model.Email); //Kommer uansett om bruker finnes eller ikke. } //Slik at ikke folk kan gjette seg frem til epost else { ModelState.AddModelError("", "Problem ved sending av mail, vennligst kontakt Kundeservice "); } } ModelState.AddModelError("", "Mail er sendt til " + model.Email); //Kommer uansett om bruker finnes eller ikke. //Slik at ikke folk kan gjette seg frem til epost return View(model); }
public bool LostPassword(LostPasswordModel model) { return _repository.LostPassword(model); }
public bool LostPassword(LostPasswordModel model) { if (model.Email == null) { return false; } return true; }
public bool resettPassord(LostPasswordModel ansatt) { return _repository.LostPassword(ansatt); }
public bool LostPassword(LostPasswordModel model) { try { if (model.Email == null || model.Email == "") return false; var crypto = new SimpleCrypto.PBKDF2(); string pass; //MembershipUser user; var UrlHelper = new UrlHelper(); var foundUser = (from u in db.Admins where u.Epost == model.Email select u).FirstOrDefault(); if (foundUser != null) { pass = SimpleCrypto.RandomPassword.Generate(); foundUser.Password = crypto.Compute(pass); foundUser.PasswordSalt = crypto.Salt; db.SaveChanges(); string resetLink = "<a href='" + UrlHelper.Action("Login", "User", "", "http") + "'>Logg Inn </a>"; string subject = "Tilbakestillt passord for dadada.no"; string body = "Nytt Passord: \" " + pass + " \" \n Logg inn her: " + resetLink; string from = "*****@*****.**"; MailMessage message = new MailMessage(from, model.Email); message.Subject = subject; message.Body = body; message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; SmtpClient client = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential("*****@*****.**", "s198774s193640"), DeliveryMethod = SmtpDeliveryMethod.Network }; try { client.Send(message); } catch (Exception) { return false; } } return true; //Kommer uansett om bruker finnes eller ikke. }//Slik at ikke folk kan gjette seg frem til epost catch (System.Data.SqlClient.SqlException ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (InvalidOperationException ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (ArgumentException ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (NullReferenceException ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (SystemException ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (Exception ex) { SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } return false; }