Ejemplo n.º 1
0
 /// <summary>
 /// Very simple method of loading the encrypted Connections file
 /// Does trap CryptographicException which occurs if the file cannot be decrypted which
 /// most likely is caused by a bad password, but could be due to a corrupted Connections file
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnLoadConnections_Click(object sender, EventArgs e)
 {
     cboConnString.Items.Clear();
     if (!string.IsNullOrEmpty(txtPassword.Text))
     {
         try
         {
             xe.Key = txtPassword.Text;
             // Open file and read strings into array, decrypt them one by one
             string[] encConnections = File.ReadAllLines("Connections.txt");
             foreach (string item in encConnections)
             {
                 cboConnString.Items.Add(xe.Decrypt(item));
             }
             MessageBox.Show("Connections loaded!", "Connection Loader", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (FileNotFoundException)
         {
             MessageBox.Show("Connections File Not Found!\n\nCreate one by clicking Connections button.", "Connection Loader", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
         catch (CryptographicException)
         {
             MessageBox.Show("Bad Password or corrupted Connections file!\n\nConnections NOT loaded!", "Connection Loader", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
         cboConnString.Refresh();
     }
     else
     {
         MessageBox.Show("Must enter the password before Loading Connections!", "Connection Maintenance", MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the password given an email (or username)
        /// </summary>
        /// <param name="sEmail"></param>
        /// <returns></returns>
        private static string GetUserPassword(string sEmail)
        {
            string sRetVal = "";

            try
            {
                string       sSql       = "SELECT Password FROM Users Where Email = @Email";
                SqlParameter paramEmail = new SqlParameter("@Email", SqlDbType.VarChar);
                paramEmail.Value = sEmail;

                SqlDataReader dt = GetDataReaderWithParams(sSql, paramEmail);
                if (dt.Read())
                {
                    XCryptEngine MyScriptEngine = null;

                    MyScriptEngine           = new XCryptEngine();
                    MyScriptEngine.Algorithm = XCryptEngine.AlgorithmType.DES;
                    MyScriptEngine.InitializeEngine();
                    sRetVal = MyScriptEngine.Decrypt(dt["Password"].ToString());// After Script Engine Init
                    MyScriptEngine.DestroyEngine();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(sRetVal);
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            if (this.encText.Text == null || this.encText.Text.Length == 0)
            {
                MessageBox.Show("No Encrypted Text Found", "Error");
                return;
            }

            this.decText.Text = "";

            InitializeEncryptionEngine();

            xe.Key            = this.keyText.Text;
            this.decText.Text = xe.Decrypt(this.encText.Text);

            if (chkClipPaste.Checked)
            {
                Clipboard.SetData(DataFormats.Text, this.encText.Text);
            }
        }