private void ChangePassword_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(currentPassword.Text) || String.IsNullOrEmpty(newPassword.Text) || String.IsNullOrEmpty(newPassword2.Text)) { MessageBox.Show(Messages.emptyFields); Logger.Log(Messages.emptyFields); } else { if (newPassword.Text.Length >= 6 && newPassword2.Text.Length >= 6) { new UserEditingService(currentUser) .UpdateSetting("password", PasswordHasher.CreateMD5(currentPassword.Text), PasswordHasher.CreateMD5(newPassword.Text), PasswordHasher.CreateMD5(newPassword2.Text), Messages.newPasswordSameAsOld, Messages.passwordUpdateSuccess, Messages.passwordUpdateFailed, Messages.passwordsDoNotMatch, Messages.passwordIncorrect); ClearValues(); } else { MessageBox.Show(Messages.passwordTooShort); Logger.Log(Messages.passwordTooShort); } } }
private bool ValidateFields(string username, string password) { var hashedPassword = PasswordHasher.CreateMD5(password); var credentialResult = SqlDriver.Fetch($"SELECT username, password FROM users WHERE username='******' AND password='******';"); return(credentialResult != null && credentialResult.Count == 1); }
/// <summary> /// Constructor /// </summary> /// <param name="pId"></param> /// <param name="pContrasenia"></param> public Usuario(string pId, string pContrasenia) { Id = pId; Contrasenia = PasswordHasher.CreateMD5 (pContrasenia); Administrador = false; }
private void UpdatePassword(string newPassword, string username) { var sqlUpdatePassword = "******" + PasswordHasher.CreateMD5(newPassword) + "' WHERE username='******';"; try { if (SqlDriver.Execute(sqlUpdatePassword)) { Logger.Log(Messages.passwordUpdateSuccess); } else { Logger.Log(Messages.passwordUpdateFailed); } } catch (Exception ex) { Logger.Log(ex.Message); } }
private void CreateAccountButton_Click(object sender, EventArgs e) { if (ValidateFields()) { var newUser = new UserModel() { Username = usernameText.Text, FirstName = firstNameText.Text, LastName = lastNameText.Text, Email = emailText.Text, University = universityBox.SelectedItem.ToString(), Status = statusBox.SelectedItem.ToString(), Password = PasswordHasher.CreateMD5(passwordText.Text), }; SendUserToDb(newUser); Hide(); var loginForm = new LoginForm(); loginForm.Closed += (s, args) => this.Close(); loginForm.ShowDialog(); } }