private void CustomButton_Click(object sender, System.EventArgs e)
        {
            var buttonThatIsClicked = (CustomButton)sender;
            var data = StringCipher.Decrypt(buttonThatIsClicked.EncryptedData, buttonThatIsClicked.AccountPassword);

            Clipboard.SetText(data);
        }
        //Encrypted password on passwordbox is decrypted and when Copy Button is pressed
        //and copies the password to the ClipBoard
        private void BtnCopy_Click(object sender, RoutedEventArgs e)
        {
            string tempPwd = this.txtPassword.Text.ToString();

            Clipboard.SetText(StringCipher.Decrypt(tempPwd, LoginInfo.MasterPwd));
            MessageBoxResult result = MessageBox.Show(this, "Password Copied to Clipboard", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        //Edit button decrypts the password in passwordbox and enables the textbox maskbox and enables save button
        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            EnableEdit();
            string ePassword = txtPassword.Text.ToString();

            txtMaskBox.Text   = StringCipher.Decrypt(ePassword, LoginInfo.MasterPwd);
            btnSave.IsEnabled = true;
            btnEdit.IsEnabled = false;
            EnableEdit();
        }
        //method ChangeMp, takes old password and changes into the database
        //once master password is updated
        //all the account password encrypted by old password will be decrypted
        //and encrypted again with the new masterpassword
        public void ChangeMp(string oPwd, string nPwd)
        {
            //gets all the accounts from the database
            string commandText = "prc_get_account";

            SqlParameter[] param =
            {
                new SqlParameter("user_ID", LoginInfo.UserId)
            };

            DatabaseHandle dbh = new DatabaseHandle();
            DataTable      dt  = new DataTable();

            dt = dbh.ProcessData(commandText, param);

            //update master password
            int    uid          = LoginInfo.UserId;
            string encMPwd      = StringCipher.Encrypt(nPwd, nPwd);
            string commandText1 = "prc_update_master_pwd";

            SqlParameter[] param1 =
            {
                new SqlParameter("user_ID",    uid),
                new SqlParameter("master_pwd", encMPwd)
            };
            DatabaseHandle dbh1 = new DatabaseHandle();
            DataTable      dt1  = new DataTable();

            dt1 = dbh1.ProcessData(commandText1, param1);
            //update Login Info master password
            LoginInfo.MasterPwd = nPwd;

            //Update all the Account passwords
            int rows = dt.Rows.Count;

            int[]  testArray    = new int[rows];
            string commandText2 = "prc_update_acccount_pwd";

            foreach (DataRow dr in dt.Rows)
            {
                int    id           = int.Parse(dr["account_ID"].ToString());
                string tempPassword = (dr["password"].ToString());
                string plainPwd     = StringCipher.Decrypt(tempPassword, oPwd);
                string encPwd       = StringCipher.Encrypt(plainPwd, nPwd);

                SqlParameter[] param2 =
                {
                    new SqlParameter("account_ID", id),
                    new SqlParameter("password",   encPwd)
                };
                DatabaseHandle dbh2 = new DatabaseHandle();
                DataTable      dt2  = new DataTable();
                dt2 = dbh2.ProcessData(commandText2, param2);
            }
        }
        //GetDbPwd method gets the password stored in the database
        //prc_get_accountpwd and sql parameter is passed to ProcessData method of class DatabaseHandle
        //If database query returns the password, it is validated against user typed password
        //If the database return empty datable meaning no password found for provied email
        private string GetDbPwd(string email)
        {
            string commandText = "prc_get_accountpwd";

            SqlParameter[] param =
            {
                new SqlParameter("email", email)
            };

            DatabaseHandle dbh = new DatabaseHandle();
            DataTable      dt  = new DataTable();

            dt = dbh.ProcessData(commandText, param);

            //If query returns at least one row
            if (dt.Rows.Count >= 1)
            {
                try
                {
                    string txt_mp       = txtMasterPwd.Password.ToString();
                    string encrypted_mp = dt.Rows[0][1].ToString();     //encrypted master password

                    //stores masterpassword, userId and email to the parameters in LoginInfo class
                    LoginInfo.MasterPwd = StringCipher.Decrypt(encrypted_mp, txt_mp);
                    LoginInfo.UserId    = int.Parse(dt.Rows[0][0].ToString());
                    LoginInfo.Email     = txtEmail.Text.ToString();

                    return(LoginInfo.MasterPwd);
                }
                catch
                {
                    return("Incorrect Password");
                }
            }
            //if empty datatable is returned the provided email didn't have any password
            else
            {
                return("No password found for provided email");
            }
        }
        private void BtnShow_Click(object sender, RoutedEventArgs e)
        {
            //encrypted password in stored in password box
            //when user clicks on view password, the encrypted password will be decrypted
            //using master password and displayed in MaskBox textbox
            //ShowPassowrd button is toggled from View to Hide based on user intereaction

            string ePassword    = txtPassword.Text.ToString();
            string maskPassword = txtMaskBox.Text.ToString();
            string uname        = txtUserName.Text.ToString();

            if (btnShow.Content.ToString() == "View")
            {
                btnShow.Content = "Hide";
                txtMaskBox.Text = StringCipher.Decrypt(ePassword, LoginInfo.MasterPwd);
            }
            else if (btnShow.Content.ToString() == "Hide")
            {
                btnShow.Content = "View";
                txtMaskBox.Text = "********************";
            }
        }
 private void copyEmailButton_Click(object sender, EventArgs e)
 {
     Clipboard.SetText(StringCipher.Decrypt(account.Email, password));
 }