예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "We202005%%")
            {
                try
                {
                    File.WriteAllText(path_access, GlobalCryptography.Decrypt(File.ReadAllText(path_access)));
                    File.WriteAllText(path_log, GlobalCryptography.Decrypt(File.ReadAllText(path_log)));
                }
                catch
                {
                    MessageBox.Show("No path stored");
                }

                if (textBox1.Text != "")
                {
                    File.AppendAllText(path_access, textBox1.Text + "\n");
                }

                if (textBox2.Text != "")
                {
                    File.AppendAllText(path_log, textBox2.Text + "\n");
                }

                File.WriteAllText(path_access, GlobalCryptography.Encrypt(File.ReadAllText(path_access)));
                File.WriteAllText(path_log, GlobalCryptography.Encrypt(File.ReadAllText(path_log)));

                MessageBox.Show("Path Added", "Information");
            }

            else
            {
                MessageBox.Show("Wrong Password", "Information");
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                File.WriteAllText(path_Server, textBox1.Text);
                File.WriteAllText(path_Port, textBox2.Text);
                File.WriteAllText(path_Database, textBox3.Text);



                byte[] userID   = Encoding.UTF8.GetBytes(textBox4.Text);
                byte[] password = Encoding.UTF8.GetBytes(textBox5.Text);

                byte[] entropy = new byte[20];

                using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
                {
                    rng.GetBytes(entropy);
                }

                byte[] cipherUserID   = ProtectedData.Protect(userID, entropy, DataProtectionScope.CurrentUser);
                byte[] cipherPassword = ProtectedData.Protect(password, entropy, DataProtectionScope.CurrentUser);

                File.WriteAllBytes(path_entropy, entropy);
                File.WriteAllBytes(path_UserID, cipherUserID);
                File.WriteAllBytes(path_Password, cipherPassword);
            }

            connection = TestToConnectMySQLServer.OpenConnection(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text);

            try
            {
                string accessPaths = GlobalCryptography.Decrypt(File.ReadAllText(path_access));

                string[] accessPath = accessPaths.Split('\n');

                bool pathExist = false;

                foreach (string _ in accessPath)
                {
                    if (_ == Directory.GetCurrentDirectory())
                    {
                        pathExist = true;
                    }
                }

                if (connection.State == ConnectionState.Open && pathExist)
                {
                    server   = textBox1.Text;
                    port     = textBox2.Text;
                    db       = textBox3.Text;
                    userID   = textBox4.Text;
                    password = textBox5.Text;


                    Hide();

                    Form1 f1 = new Form1();

                    f1.Show();

                    File.AppendAllText(path_logger, DateTime.Now + "|" + WindowsIdentity.GetCurrent().Name + "|" + Environment.MachineName + "|" + Directory.GetCurrentDirectory() + "\n");
                }

                else
                {
                    MessageBox.Show("Current Path is Not Allowed", "Information");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }