Esempio n. 1
0
        public async Task <ActionResult> ForgotYourPassword(ForgotPasswordModel model)
        {
            var usermanager = IdentityTools.NewUserManager();
            var userstore   = IdentityTools.NewUserStore();
            var user        = await userstore.FindByEmailAsync(model.Email);

            if (user != null && user.Email == model.Email)
            {
                Random rnd         = new Random();
                string str         = "qwertyuopilkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890.,*";
                string NewPassword = "";
                for (int i = 0; i < 7; i++)
                {
                    NewPassword += str[rnd.Next(str.Length)];
                }
                await userstore.SetPasswordHashAsync(user, usermanager.PasswordHasher.HashPassword(NewPassword));

                var result = userstore.Context.SaveChanges();

                MailMessage message = new MailMessage();
                message.From = new MailAddress("*****@*****.**");
                message.To.Add(model.Email);
                message.Body       = "Sayın " + user.Name + " " + user.Surname + " şifreniz " + NewPassword + " olarak güncellenmiştir. İyi çalışmalar dileriz.";
                message.IsBodyHtml = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Credentials = new NetworkCredential("*****@*****.**", "Besiktas1903.");
                client.EnableSsl   = true;
                client.Send(message);

                return(RedirectToAction("Login"));
            }
            else
            {
                return(View());
            }
        }