Example #1
0
        /// <summary>
        /// Handler when an admin wants to add a new user to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void onAddNewUserClicked(object sender, EventArgs e)
        {
            //Check if the the input values are correct.
            if (this.adminComboBoxPermissionGroup.SelectedIndex != -1 && this.adminInputNewUsername.Text.Length > 0)
            {
                //Generate password and convert it to a hash.
                ARA_Login loginHandler   = new ARA_Login();
                string    randomPassword = loginHandler.generateRandomPassword(ARA_Constants.randomPasswordLength);
                byte[]    passwordHash   = loginHandler.getHashFromByteArray(loginHandler.GetBytes(randomPassword));

                //Insert new user in the database.
                this.tbl_UserTableAdapter.Insert(this.adminInputNewUsername.Text, passwordHash, (Int32)this.adminComboBoxPermissionGroup.SelectedValue);
                this.dataGridView1.DataSource = this.tbl_UserTableAdapter.GetData();

                //Give the admin a pop-up and copy the new password to the users clipboard.
                MessageBox.Show(ARA_Constants.messageBoxLoginNewUser, ARA_Constants.messageBoxLoginNewUserHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);

                //Clean the login handler form memory.
                loginHandler = null;
            }
        }