예제 #1
0
        private void btnForgot_Click(object sender, RoutedEventArgs e)
        {
            client.Port                  = 587;
            client.Host                  = "smtp.gmail.com";
            client.EnableSsl             = true;
            client.Timeout               = 10000;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential(mail, pass);

            var guid     = Guid.NewGuid();
            var validate = context.Suppliers.Where(x => x.Email.Contains(txtEmail.Text)).SingleOrDefault();
            var fill     = "Hi " + validate.Name + "\n\n"
                           + "Try this Password to get into reset password: \n"
                           + guid
                           + "\n\nThank You";

            MailMessage mm = new MailMessage("*****@*****.**", txtEmail.Text, "Forgot Email", fill);

            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            client.Send(mm);

            var bcrypt = Bcrypt.HashPassword(guid.ToString());
            var getId  = context.Suppliers.Find(Convert.ToInt32(validate.Id));

            getId.Name  = validate.Name;
            getId.Email = validate.Email;
            getId.Pass  = "";
            getId.Guid  = Bcrypt.HashPassword(bcrypt);
            context.SaveChanges();
            MessageBox.Show("Check Your Email");
            LoginWindow login = new LoginWindow();

            login.Show();
            this.Close();
        }