コード例 #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            // TODO Verify password and repeated password
            if (passwordTextBox.Text.Length < 5)
            {
                throw new ArgumentException("Password needs to be at least 5 characters.");
            }
            if (passwordTextBox.Text != repeatPasswordTextBox.Text)
            {
                throw new ArgumentException("Passwords do not match.");
            }

            if (openDialogImage == null)
            {
                throw new ArgumentException("You haven't selected an image.");
            }

            var encryptedPass = StringCipher.Encrypt(passwordTextBox.Text, this.password);

            SqliteDataAccess.SaveAccountItem(new AccountItemModel()
            {
                AccountId = this.account.Id, Image = openDialogImage, ImagePassword = encryptedPass
            });
            VisualizeMostRecentAccountData();

            ButtonsResetDefaultProperties();
        }
コード例 #2
0
        //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);
            }
        }
コード例 #3
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            //stores emails from text box to local variables
            string email   = txtEmail.Text.ToString();
            string dbEmail = "";
            string pwd1    = txtPwd1.Password.ToString();
            string pwd2    = txtPwd2.Password.ToString();
            //Encrypts password provided by the user
            string encryptedPassword = StringCipher.Encrypt(pwd1, pwd1);

            //if both password fields match
            if (pwd1 == pwd2)
            {
                //Checks the validity of the email address provided
                if (IsEmailvalid(email))
                {
                    //password must be from 8 to 28 character long
                    //should contain at least one number, one Uppercase and one lowercase
                    if (IsPasswordValid(pwd1))
                    {
                        //checks if the database already has that email address
                        dbEmail = CheckExistingAccount(email);
                        //if database email matches the email provided by user
                        //Message box will show the warning
                        if (dbEmail == email)
                        {
                            MessageBox.Show("Email " + email +
                                            " already exist in the Database. \nPlease use different email or LOGIN", "Existing Account", MessageBoxButton.OK);
                            btnSave.IsEnabled = false;
                        }
                        else
                        {
                            //if the email address doesn't match in the database
                            //saves email and password to the database
                            string message = SaveAccountToDB(email, encryptedPassword);
                            MessageBox.Show(message, "Account Created", MessageBoxButton.OK);
                            btnSave.IsEnabled = false;
                        }
                    }
                }
                else
                {
                    //if the the email is in invalid format
                    MessageBox.Show("The email Address you provided is not in Valid format\n" +
                                    "Please Try again", "Invalid Email", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                //password and verify password doesn't match
                MessageBox.Show("Your password doesn't match", "Warning!", MessageBoxButton.OK);
            }
        }
コード例 #4
0
        //Saves the Edit made to the passwords
        //Changes made to the password is Encrypted before saving it to the datbase
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            string      ePassword  = StringCipher.Encrypt(txtMaskBox.Text.ToString(), LoginInfo.MasterPwd);
            DataRowView row        = (DataRowView)dtaGridAccount.SelectedItem;
            int         account_ID = (int)row["account_ID"];

            EditPassword(account_ID, ePassword);
            btnEdit.IsEnabled   = false;
            btnSave.IsEnabled   = false;
            btnDelete.IsEnabled = false;
            btnShow.IsEnabled   = false;
            txtMaskBox.Text     = "";
            DisableEdit();
            MessageBox.Show("Password changed in Database Sucessfully", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);
            LoadDataDataGrid();
        }
コード例 #5
0
        //Saves username and password to the database
        //calls ProcessData method of class DatabaseHandle
        //Procedure prc_add_pwd and sql parameter is passed to ProcessData of class DatabaseHandle
        //password provided by the user is encrypted before saving to database
        //using Encrypt method of StringCipher class
        public void AddPasswordDb()
        {
            string accountName       = txtAccountName.Text.ToString();
            string userName          = txtUsrName.Text.ToString();
            string password          = txtPwd.Password.ToString();
            string encryptedPassword = StringCipher.Encrypt(password, LoginInfo.MasterPwd);
            string notes             = txtNote.Text.ToString();
            var    date = DateTime.Now.ToString("yyyy/MM/dd");

            string commandText = "prc_add_pwd";

            SqlParameter[] param =
            {
                new SqlParameter("@account_name", accountName),
                new SqlParameter("@user_ID",      LoginInfo.UserId),
                new SqlParameter("@username",     userName),
                new SqlParameter("@password",     encryptedPassword),
                new SqlParameter("@notes",        notes),
            };
            DatabaseHandle dbh = new DatabaseHandle();
            DataTable      dt  = new DataTable();

            dt = dbh.ProcessData(commandText, param);
        }