AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Documentation on customizing default password hashing

Open Kool-Koder opened this issue 7 years ago • 11 comments

Hi, I can't seem to find the tutorial for customizing Identity default password hashing. With reference to this article, may I know if what is stated inside is correct? ASP.NET Identity Version 2: PBKDF2 with HMAC-SHA1, 128-bit salt, 256-bit subkey, 1000 iterations Thank you!


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Kool-Koder avatar Jan 16 '19 08:01 Kool-Koder

Yes, that's correct. You can see for yourself in the source code.

serpent5 avatar Jan 16 '19 12:01 serpent5

How am I able to specify which version to use? Thank you!

Kool-Koder avatar Jan 16 '19 13:01 Kool-Koder

You can add something like the following to ConfigureServices:

services.Configure<PasswordHasherOptions>(
    o => o.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);

serpent5 avatar Jan 16 '19 13:01 serpent5

I see nice. Thank you very much! :)

Kool-Koder avatar Jan 16 '19 13:01 Kool-Koder

Yes, we need to cover PasswordHasherOptions in the auth docs. Thanks for opening.

guardrex avatar Jan 16 '19 13:01 guardrex

Yes, helpful b/c we often can make faster/better doc updates following discussion.

guardrex avatar Jan 16 '19 14:01 guardrex

You can add something like the following to ConfigureServices:

services.Configure<PasswordHasherOptions>(
    o => o.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);

Hi, I just tried the above code and regardless whether it's V2 or V3 I could login to the database without changing anything. Is there anything else I missed? From my understanding V2 and V3 should result in different hash and therefore the user would be unable to login.

Kool-Koder avatar Jan 16 '19 18:01 Kool-Koder

The hashed password is different, but the first byte specifies which version of the hashing algorithm was actually used. When verifying a password against a hash, the VerifyHashedPassword method is able to select the correct algorithm to use based on this "format marker" byte and so the user can log in regardless of which version of the algorithm was used. The PasswordHasherCompatibilityMode is used to specify which algorithm gets used when hashing new passwords.

serpent5 avatar Jan 16 '19 20:01 serpent5

@serpent5 I nominate you for ...

🥇 Answer of the Day 🥇

Getting the .NET Foundation to send you a free case of :beer: is another matter tho. I have a feeling that I'm not going to get a lot of traction with that idea! 😁 lol

guardrex avatar Jan 16 '19 20:01 guardrex

Great answer @serpent5 Thank you very much for sharing. Your help is much appreciated

Kool-Koder avatar Jan 17 '19 01:01 Kool-Koder

@guardrex Thanks! They say it's the thought that counts... 🤔

@Kool-Koder It's no problem at all. Glad to be able to help. 😃

serpent5 avatar Jan 17 '19 08:01 serpent5