/// <summary> /// Handler when login button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loadingScreenButtonLoginClicked(object sender, EventArgs e) { //Did the user put in some values. if (this.loadingScreenInputUsername.Text.Length > 0) { //Convert password to a hash. ARA_Login loginHandler = new ARA_Login(); //Try to login the user. if (loginHandler.login()) { loginHandler = null; //Add log message. ARA_Events.triggerUserLoggedInEvent(); this.Hide(); ARA_BaseForm mainApp = new ARA_BaseForm(); mainApp.Closed += (s, args) => this.Close(); mainApp.Show(); } else { MessageBox.Show(ARA_Constants.messageBoxLoginFailded, ARA_Constants.messageBoxLoginFaildedHeader, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// When our form loads, start the backgroundworker. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ARA_LoadingScreen_Load(object sender, EventArgs e) { //Set username from system. ARA_Login login = new ARA_Login(); this.loadingScreenInputUsername.Text = login.getLoggedInUserName(); this.loadingScreenInputUsername.Invalidate(); //Start checking stuff on the backgroundworker. backgroundWorker1.RunWorkerAsync(); }
/// <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; } }