private void button1_Click(object sender, EventArgs e)
        {
            Regex reg = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");

            if (!reg.IsMatch(emailtxt.Text))
            {
                MessageBox.Show("Geçersiz Mail Adresi");
                return;
            }
            string sifre      = CreatePassword(6);
            string emailsorgu = "select * from Kullanici where Email='" + emailtxt.Text + "'";

            if (DataBase.select(emailsorgu).Rows.Count > 0)
            {
                DataTable   table  = DataBase.select(emailsorgu);
                MailMessage ePosta = new MailMessage();
                ePosta.From = new MailAddress("*****@*****.**");
                ePosta.To.Add(emailtxt.Text);
                ePosta.Subject = "parola yenile";
                ePosta.Body    = sifre;
                SmtpClient smtp = new SmtpClient();
                smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "asasas123123123");
                smtp.Port        = 587;
                smtp.Host        = "smtp.gmail.com";
                smtp.EnableSsl   = true;
                object userState = ePosta;
                bool   kontrol   = true;
                try
                {
                    smtp.SendAsync(ePosta, (object)ePosta);
                    string kodekle = "INSERT INTO SifremiUnuttum(Mail,Kod,Kid,Olusturulan_Tarih,Durum) Values('"
                                     + emailtxt.Text + "','" + sifre + "','" + table.Rows[0]["KullaniciId"].ToString() + "','" + DateTime.Today.ToString("yyyy-MM-dd") + "','1')";
                    DataBase.ExecSql(kodekle);
                    string              sorgu = "Select KullaniciId from Kullanici where Email='" + emailtxt.Text.Trim() + "'";
                    DataTable           tbl   = DataBase.select(sorgu);
                    frmSifreYenilemeKod frmSifreYenilemeKod = new frmSifreYenilemeKod();
                    frmSifreYenilemeKod.kullaniciid = tbl.Rows[0]["KullaniciId"].ToString();
                    frmSifreYenilemeKod.Show();
                    this.Hide();
                }
                catch (SmtpException ex)
                {
                    kontrol = false;
                    System.Windows.Forms.MessageBox.Show(ex.Message, "Mail Gönderme Hatasi");
                }
            }
            else
            {
                MessageBox.Show("Mail Adresine Kayıtlı Kullanıcı Yoktur..");
            }
        }
 private void button1_Click_1(object sender, EventArgs e)
 {
     try
     {
         string    kullaniciadi = "select * from Kullanici where KullaniciAdi='" + textBox1.Text + "'";
         DataTable tbl          = DataBase.select(kullaniciadi);
         if (tbl.Rows.Count > 0)
         {
             string sifreyenilemekontrol = "Select * from SifremiUnuttum where Kid='" + tbl.Rows[0]["KullaniciId"].ToString() + "' and Durum=1";
             if (DataBase.select(sifreyenilemekontrol).Rows.Count > 0)
             {
                 MessageBox.Show("Daha Önceden Şifre Yenileme İsteğinde Bulunduğunuz İçin Şifre Yenileme Sayfasına Yönlendiriliyorsunuz");
                 frmSifreYenilemeKod sifreYenilemeKod = new frmSifreYenilemeKod();
                 sifreYenilemeKod.kullaniciid = tbl.Rows[0]["KullaniciId"].ToString();
                 sifreYenilemeKod.Show();
                 return;
             }
             string kullanici = "select * from Kullanici where KullaniciAdi='" + textBox1.Text + "' and Sifre='" + textBox2.Text + "'";
             if (DataBase.select(kullanici).Rows.Count > 0)
             {
                 table = DataBase.select(kullanici);
                 Anasayfa anasyf = new Anasayfa();
                 anasyf.kladi = table.Rows[0]["Adi"].ToString() + " " + table.Rows[0]["Soyadi"].ToString();
                 mail         = table.Rows[0]["Email"].ToString();
                 kullaniciid  = table.Rows[0]["KullaniciId"].ToString();
                 anasyf.Show();
                 this.Hide();
             }
             else
             {
                 MessageBox.Show("Kullanıcı Adı Veya Şifre Yanlış");
             }
         }
         else
         {
             MessageBox.Show("Kullanıcı Adı Veya Şifre Yanlış");
         }
     }
     catch (Exception hata)
     {
         MessageBox.Show(hata.Message);
     }
 }