private void btn_Submit_Click(object sender, EventArgs e) { SaltUserPassword createUser = new SaltUserPassword(); string hashedPassword = createUser.PasswordSaltHash(txt_Password.Text); if (txt_UserName.Text == "" || txt_Password.Text == "") { MessageBox.Show("Please provide UserName and Password"); return; } try { SqlConnection con = new SqlConnection(cs); con.Open(); SqlCommand cmd = new SqlCommand("spAddUser", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@UserName", txt_UserName.Text)); cmd.Parameters.Add(new SqlParameter("@PassWord", hashedPassword)); cmd.ExecuteNonQuery(); con.Close(); this.Hide(); MessageBox.Show("The User Has Been Created"); MainUI fm = new MainUI(); fm.Show(); } catch (SqlException ex) { MessageBox.Show(ex.Message); } }
public void CanSaltHashDehashDesalt() { CU = new SaltUserPassword(); CP = new CheckPassword(); string SaltedAndHashedPassword = CU.PasswordSaltHash("1"); CP.txt_Password = SaltedAndHashedPassword; CP.txt_UserName = "******"; try { CP.CheckIfLoginIsAccepted(); } catch (UnauthorizedAccessException) { } Assert.IsTrue(CP.AccessAllowed); }