Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                int ex = valid();
                if (ex == 1)
                {
                    if ((MessageBox.Show("Give Valid Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) == DialogResult.OK))
                    {
                        Application.UseWaitCursor.ToString();
                    }
                }
                if (ex == 0)
                {
                    Database db        = new Database();
                    string[] strin     = db.selectQuery("select pwd,secret from reg where uname='" + comboBox1.SelectedItem.ToString() + "'");
                    string   password  = strin[0].ToString();
                    string   secretKey = strin[1].ToString();


                    if (comboBox1.Text == "" || textBox1.Text == "" || textBox2.Text == "")
                    {
                        MessageBox.Show("Please Fill up All Text Boxes");
                    }
                    else if (textBox1.Text != password || textBox2.Text != secretKey)
                    {
                        MessageBox.Show("Pass Word & Secret Key Mismatch");
                    }
                    else if (textBox1.Text == password && textBox2.Text == secretKey)
                    {
                        //SendData sd = new SendData();
                        //sd.Show();
                        byte[]    data = new byte[1024];
                        string    input, strdata;
                        TcpClient Server1;
                        int       recv;
                        try
                        {
                            //Give the IP Address of Trusted Center's
                            Server1 = new TcpClient("localhost", 5555);
                        }
                        catch (SocketException)
                        {
                            MessageBox.Show("Unable to connect Main Server...");
                            return;
                        }

                        NetworkStream ns = Server1.GetStream();
                        input = comboBox1.SelectedItem.ToString();
                        string flag = "send";
                        if (input != "exit")
                        {
                            ns.Write(Encoding.ASCII.GetBytes(flag), 0, flag.Length);
                            ns.Write(Encoding.ASCII.GetBytes(secretKey), 0, secretKey.Length);
                            ns.Write(Encoding.ASCII.GetBytes(input), 0, input.Length);

                            recv    = ns.Read(data, 0, data.Length);
                            strdata = Encoding.ASCII.GetString(data, 0, recv);
                            Int32 aa = Convert.ToInt32(strdata);
                            int   y  = strdata.Length;
                            long  t  = hashing(aa, y);
                            MessageBox.Show("Quantum Key : " + t);

                            //SqlCommand cmd1 = new SqlCommand("insert into qkey values("+t+"),con");
                            //cmd1.ExecuteNonQuery();
                            SendData sd = new SendData(t.ToString());
                            sd.Show();
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                String ee = ex.Message;
                MessageBox.Show(ee);
            }
        }