private void TryToConnect() { string passwordEntered = passwordTextBox.Text; LoginTools.Login = userTextBox.Text; LoginTools.HashedPassword = LoginTools.Sha256_hash(passwordEntered); try { if (LoginTools.CheckConnection()) { if (LoginTools.Employee.EstLicencie) { throw new UnauthorizedAccessException("Cet utilisateur n'a pas la permission d'accéder à l'application"); } _appWindow.Login(); } else { errorLabel.Visible = true; passwordTextBox.Text = ""; } } catch (UnauthorizedAccessException exception) { MessageBox.Show(exception.Message); } }
private void OkButton_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { if (surnameTextBox.Text == "" || nameTextBox.Text == "" || emailTextBox.Text == "" || phoneTextBox.Text == "" || loginTextBox.Text == "" || passwordTextBox.Text == "") { throw new Exception(Resources.compulsary_values_exception); } if (surnameTextBox.Text.Any(char.IsDigit)) { throw new Exception("Le prénom ne peut contenir de valeur numérique."); } if (nameTextBox.Text.Any(char.IsDigit)) { throw new Exception("Le nom ne peut contenir de valeur numérique."); } try { _newEmployee.Personne.Email = new MailAddress(emailTextBox.Text).ToString(); } catch (FormatException) { throw new Exception(Resources.unrecognized_email); } _newEmployee.Personne.Nom_Personne = surnameTextBox.Text; _newEmployee.Personne.Prenom_Personne = nameTextBox.Text; _newEmployee.Personne.Date_Naissance = birthDateTimePicker.Value.Date; _newEmployee.Personne.Telephone = phoneTextBox.Text; _newEmployee.Personne.Adresse = addressTextBox.Text; _newEmployee.Personne.Email = emailTextBox.Text; _newEmployee.Login = loginTextBox.Text; _newEmployee.Password = LoginTools.Sha256_hash(passwordTextBox.Text); _db.Employe.Add(_newEmployee); _db.SaveChanges(); Close(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void OkButton_Click(object sender, EventArgs e) { if (oldPasstextBox.Text == "" || newPassTextBox.Text == "" || confirmPassTextBox.Text == "") { MessageBox.Show(Resources.some_not_filled); } else if (LoginTools.Sha256_hash(oldPasstextBox.Text) != _concernedEmployee.Password) { MessageBox.Show(Resources.old_pass_incorrect); } else if (newPassTextBox.Text != confirmPassTextBox.Text) { MessageBox.Show(Resources.not_corresponding_messages); } else { _concernedEmployee.Password = LoginTools.Sha256_hash(newPassTextBox.Text); Close(); } }
public void Sha256FailedTest() { Assert.IsFalse(LoginTools.Sha256_hash("unpremiersha").Equals(LoginTools.Sha256_hash("unautresha"))); }
public void Sha256SuccessfulTest() { Assert.IsTrue(LoginTools.Sha256_hash("lesha").Equals(LoginTools.Sha256_hash("lesha"))); }
public void CheckConnectionFailedWithoutPermissionTest() { LoginTools.Login = "******"; LoginTools.HashedPassword = LoginTools.Sha256_hash("1234"); Assert.IsFalse(LoginTools.CheckConnection()); }
public void CheckConnectionFailedTest() { LoginTools.Login = "******"; LoginTools.HashedPassword = LoginTools.Sha256_hash("false"); Assert.IsFalse(LoginTools.CheckConnection()); }
public void CheckConnectionSuccessfulTest() { LoginTools.Login = "******"; LoginTools.HashedPassword = LoginTools.Sha256_hash("success"); Assert.IsTrue(LoginTools.CheckConnection()); }