Hashing In ASP.NET Core 2.0

Problem

How to use hash data (e.g. passwords) in ASP.NET Core.

Solution

The new Data Protection API in .NET Core includes functionality to create hashes using PBKDF2algorithm. ASP.NET Core uses this behind the scenes functionality in PasswordHasher class, which is used in ASP.NET Core Identity.

Create a class library and add the following NuGet package - 

Microsoft.AspNetCore.Cryptography.KeyDerivation

Add a class to encapsulate the hashing logic.

Add a class to encapsulate the logic for creating a random salt.

Add tests to verify the functionality, e.g,

Source Code

GitHub

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now