Example #1
0
        public ResultSetViewModel ForgotPassword(string email)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var objUser = db.Users.Where(d => d.Email == email).FirstOrDefault();
                    if (objUser != null)
                    {
                        try
                        {
                            var          fromAddress  = new MailAddress("*****@*****.**", "AutoMax");
                            var          toAddress    = new MailAddress(email);
                            const string fromPassword = "******";
                            const string subject      = "Forgot Password";
                            var          tokenis      = Guid.NewGuid().ToString();
                            string       body         = "Dear " + objUser.FirstName + " " + objUser.LastName + ", <br/ ><br/ >"
                                                        + "Please find below a reminder of your password as requested. This message has been sent only to the email address used in your account. <br/ ><br/ >"
                                                        + "Your Password is : <b>" + EncrypterDecrypter.Decrypt(objUser.Password) + "</b> <br/ ><br/ >"
                                                        + "Thank you for your patience. Have a nice day ! <br/ ><br/ >Regards,<br/ >Support Team<br/ >Automax";
                            var smtp = new SmtpClient
                            {
                                Host                  = "smtp.gmail.com",
                                Port                  = 587,
                                EnableSsl             = true,
                                DeliveryMethod        = SmtpDeliveryMethod.Network,
                                UseDefaultCredentials = false,
                                Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                            };
                            using (var message = new MailMessage(fromAddress, toAddress)
                            {
                                Subject = subject,
                                IsBodyHtml = true,
                                Body = body
                            })
                            {
                                smtp.Send(message);
                            }

                            return(new ResultSetViewModel("Email sent successfully with password instruction."));
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        throw new Exception("User does not exist, please try again. Thanks");
                    }
                }

                throw new Exception("Please enter valid email and try again. Thanks");
            }
            catch (Exception ex)
            {
                return(new ResultSetViewModel(ex));
            }
        }
Example #2
0
 private void btnDecrypt_Click(object sender, EventArgs e)
 {
     try
     {
         txtOutput.Text = EncrypterDecrypter.Decrypt(txtInput.Text, txtPassword.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #3
0
 private void Decrypt_Clicked(object sender, EventArgs e)
 {
     try
     {
         entryOutput.Text = EncrypterDecrypter.Decrypt(entryInput.Text, entryPwd.Text);
         startTimer();
     }
     catch (Exception ex)
     {
         DisplayAlert("Error:", ex.Message, "OK");
     }
 }
Example #4
0
 public ActionResult ForgotPassword(ForgotPasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         var objUser = db.Users.Where(d => d.Email == model.Email).FirstOrDefault();
         if (objUser != null)
         {
             try
             {
                 var          fromAddress  = new MailAddress("*****@*****.**", "AutoMax");
                 var          toAddress    = new MailAddress(model.Email);
                 const string fromPassword = "******";
                 const string subject      = "Forgot Password";
                 var          tokenis      = Guid.NewGuid().ToString();
                 string       body         = "Dear " + objUser.FirstName + " " + objUser.LastName + ", <br/ ><br/ >"
                                             + "Please find below a reminder of your password as requested. This message has been sent only to the email address used in your account. <br/ ><br/ >"
                                             + "Your Password is : <b>" + EncrypterDecrypter.Decrypt(objUser.Password) + "</b> <br/ ><br/ >"
                                             + "Thank you for your patience. Have a nice day ! <br/ ><br/ >Regards,<br/ >Support Team<br/ >Automax";
                 var smtp = new SmtpClient
                 {
                     Host                  = "smtp.gmail.com",
                     Port                  = 587,
                     EnableSsl             = true,
                     DeliveryMethod        = SmtpDeliveryMethod.Network,
                     UseDefaultCredentials = false,
                     Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                 };
                 using (var message = new MailMessage(fromAddress, toAddress)
                 {
                     Subject = subject,
                     IsBodyHtml = true,
                     Body = body
                 })
                 {
                     smtp.Send(message);
                 }
                 ViewBag.EmailID = model.Email;
                 return(View(model));
             }
             catch (Exception)
             {
                 return(View(model));
             }
         }
         else
         {
             ModelState.AddModelError("", "User Doesn't exists");
             return(View(model));
         }
     }
     ModelState.AddModelError("", "Please enter valid emial");
     return(View(model));
 }
Example #5
0
        // GET: Users/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

            user.Password = EncrypterDecrypter.Decrypt(user.Password);
            if (user == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserRoleID = new SelectList(db.UserRoles, "UserRoleID", "Role", user.UserRoleID);

            return(View(user));
        }