23 Mayıs 2013 Perşembe

C# Login işlemleri ( Alıntı ) Sql Injection Açıgı login işlemlerinde nasıl kapatılır ?


bool kontrolsonuc = YasakliKelime(textBox1.Text + "" + textBox2.Text);
                    if (kontrolsonuc)
                    {
                        System.Data.SqlClient.SqlConnection connection1 = new System.Data.SqlClient.SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=BitProje;Integrated Security=True");
                        connection1.Open();
                        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM [SisYonLogin] WHERE [KullanıcıAdı]= @ad and Parola=@parola", connection1);

                        cmd.Parameters.Add("@ad", textBox1.Text);
                        cmd.Parameters.Add("@parola", textBox2.Text);
                        DataTable dt = new DataTable();
                        System.Data.SqlClient.SqlDataAdapter adaptor1 = new System.Data.SqlClient.SqlDataAdapter(cmd);
                        adaptor1.Fill(dt);
                        if (dt.Rows.Count == 1)
                        {

                            Form1 form1 = new Form1();
                            form1.Show();
                            this.Visible = false;

                            form1.homeRibbonPage.Text = "Sistem Yöneticisi";
                        }
                        else
                        {
                            MessageBox.Show("Yanlış kullanıcı adı veya parola girdiniz !", "HATA !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            textBox1.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Yasaklı karakter girdiniz !", "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox1.Focus();
                    }
                    textBox1.Clear();
                    textBox2.Clear();

                }

 public bool YasakliKelime(string kontrol)
        {
            string[] kullanicistring = kontrol.Split(' ');
            List<string> yasaklikelimeler = new List<string>
                (
                    new string[]{"select","delete","update","from","set","or","where","join",
                    "insert","into","alert","alter","OR"});

            for (int i = 0; i < kullanicistring.Length; i++)
            {
                if (yasaklikelimeler.Find(n => n == kullanicistring[i].ToString()) != null)
                { 
                    return false; 
                }
               
            }
            return true;
        }



Kodlar Denenmedi!..
Alıntılanan Adres: http://social.msdn.microsoft.com/Forums/tr-TR/csharptr/thread/e843b2d5-5150-41c2-84e6-51007e600c2e

Hiç yorum yok: