Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you modifying the NHibernate-based membership provider, or stuck using it out of the box? If the latter, it doesn't look like there's any extensibility. </p> <p>The ASP.NET SqlMembershipProvider works by accepting the name of a hash algorithm, conjures an instance via <a href="http://msdn.microsoft.com/en-us/library/wet69s13" rel="nofollow">HashAlgorithm.Create(name)</a> and then behaves a little differently if the algorithm type turns out to be a KeyedHashAlgorithm or regular (non-keyed) HashAlgorithm. The Zetetic.Security package is just providing a little bit of glue to make BCrypt and PBKDF2 compatible with that model.</p> <p>The sample code from NHMembershipProvider can't take advantage of that because it's very directly relying on HMACSHA1. I'd note that HMACSHA1 is not a secure algorithm for this purpose, nor is using a static salt for all users acceptable (it's scarcely better than no salt). The app ValidationKey and HMACSHA1 are meant for message integrity only.</p> <p>Here's a sample:</p> <pre><code>public class HashDemo { private static readonly RNGCryptoServiceProvider s_rng = new RNGCryptoServiceProvider(); public string HashPassword(string pwd, string hashName) { var alg = HashAlgorithm.Create(hashName); if (alg == null) throw new ArgumentException("Invalid hash name", "hashName"); byte[] tohash = System.Text.Encoding.UTF8.GetBytes(pwd); var ka = alg as KeyedHashAlgorithm; if (ka != null) { if (ka.Key == null || ka.Key.Length == 0) { byte[] key = new byte[20]; s_rng.GetBytes(key); ka.Key = key; } else { s_rng.GetBytes(ka.Key); } // TODO: return base64(ka.Key || alg.ComputeHash(tohash)) } else { var salt = new byte[20]; s_rng.GetBytes(salt); using (var ms = new System.IO.MemoryStream(salt)) { ms.Write(tohash, 0, tohash.Length); tohash = ms.ToArray(); } // TODO: return base64(salt || alg.ComputeHash(tohash)) } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload