private void SaveData_Click(object sender, RoutedEventArgs e) { //Get the button that sent the event var button = (sender as Button); //Get the name of the button var name = button.Name; //Get the right password var password = name == "admin" ? AdminPassword : TeacherPassword; //Conformation message var box = MessageBox.Show("Confirm Change " + name + " password = "******"Conform Change", MessageBoxButton.OKCancel); if (box == MessageBoxResult.OK) { if (name == "admin") { //Generate the salts for the new passwords var adminSalt = CheckPassword.GenerateSalt(8); //Set the values Properties.Settings.Default.Password = Convert.ToBase64String(CheckPassword.GenerateHash(Encoding.UTF8.GetBytes(AdminPassword.Password), adminSalt, 1000)); Properties.Settings.Default.AdminSalt = Convert.ToBase64String(adminSalt); } else { //Create the salt for the new password var teacherSalt = CheckPassword.GenerateSalt(8); //Set the values Properties.Settings.Default.TeacherPassword = Convert.ToBase64String(CheckPassword.GenerateHash(Encoding.UTF8.GetBytes(TeacherPassword.Password), teacherSalt, 1000)); Properties.Settings.Default.TeacherSalt = Convert.ToBase64String(teacherSalt); } try { Properties.Settings.Default.Save(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var message = string.Format("Success!\nNew {0} password = {1}", name, password.Password); MessageBox.Show(message, "Saved Passwords!", MessageBoxButton.OK, MessageBoxImage.Asterisk); } }
private static void SetCancelIsPressed(CheckPassword CheckForm, CheckPasswordBindingModel checkPasswordBindingModel) { checkPasswordBindingModel.CancelIsPressed = true; CheckForm.Close(); }
//Syncronous method of SetCancelIsPressedAsync public static void SetCancelIsPressedNonAsync(CheckPassword CheckForm, CheckPasswordBindingModel checkPasswordBindingModel) { SetCancelIsPressed(CheckForm, checkPasswordBindingModel); }
public static async void SetCancelIsPressedAsync(CheckPassword CheckForm, CheckPasswordBindingModel checkPasswordBindingModel) { //Uses CheckPassword Form to close the specific form. //Uses CheckPasswordBindingModel to set that cancel is pressed on that form. await Task.Run(() => SetCancelIsPressed(CheckForm, checkPasswordBindingModel)); }
//Syncronous method of CheckIfTextBoxIsEmptyAsync public static void CheckIfTextBoxIsEmptyNonAsync(string textBoxText, string textBox2Text, CheckPassword CheckForm, CheckPasswordBindingModel checkPasswordBindingModel) { if (textBoxText != "" && textBox2Text != "") { SetCheckPasswordBindingModel(textBoxText, textBox2Text, checkPasswordBindingModel); SetCheckFileBindingModelOKIsPressed(checkPasswordBindingModel); CheckForm.Close(); } else { ShowMessageBox(); } }
public static async void CheckIfTextBoxIsEmptyAsync(string textBoxText, string textBox2Text, CheckPassword CheckForm, CheckPasswordBindingModel checkPasswordBindingModel) { //uses string textBoxText and textBox2Text to get user input for the password and the IV for decryption. //uses CheckPassword Form to close the specific Form //uses CheckPasswordBindingModel to set its properties. if (textBoxText != "" && textBox2Text != "") { await Task.Run(() => SetCheckPasswordBindingModel(textBoxText, textBox2Text, checkPasswordBindingModel)); await Task.Run(() => SetCheckFileBindingModelOKIsPressed(checkPasswordBindingModel)); CheckForm.Close(); } else { await Task.Run(() => ShowMessageBox()); } }