Exemple #1
0
 public void Register(string username, string password)
 {
     using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
     {
         conn.Open();
         using (SqlCommand cmd = conn.CreateCommand())
         {
             var    salt       = HashingHelper.GenerateSalt();
             string saltedHash = HashingHelper.HashPassword(password, salt);
             string sql        = "INSERT INTO Users (Email, PasswordHash, Salt) VALUES (@email,@pwhash, @salt)";
             cmd.Parameters.AddWithValue("email", username);
             cmd.Parameters.AddWithValue("pwhash", saltedHash);
             cmd.Parameters.AddWithValue("salt", salt);
             cmd.CommandText = sql;
             cmd.ExecuteNonQuery();
         }
     }
 }
Exemple #2
0
 private void btnHash_Click(object sender, EventArgs e)
 {
     txtHashOutput.Text = HashingHelper.HashPassword(txtHashInput.Text, HashingHelper.GenerateSalt());
 }