ASP.NET MVC: Custom Password Hasher with ASP.NET Identity
By FoxLearn 5/29/2017 9:21:44 PM 9.18K
How to Custom encrypt password hasher with ASP.NET Identity MVC 5 using C#, Entity Framework Code First
Step 1: Create an Encrypt class as below
public class Encrypt { public static string GetMD5Hash(string input) { //Encrypt text using md5 using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { byte[] b = System.Text.Encoding.UTF8.GetBytes(input); b = md5.ComputeHash(b);//Hash data System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (byte x in b) sb.Append(x.ToString("x2"));//hexadecimal return sb.ToString(); } } }
Step 2: Create a custom CustomPasswordHasher class as below
public class CustomPasswordHasher : IPasswordHasher { public string HashPassword(string password) { return Encrypt.GetMD5Hash(password); } public PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword) { if (hashedPassword == HashPassword(providedPassword)) return PasswordVerificationResult.Success; else return PasswordVerificationResult.Failed; } }
Step 3: Open IdentityConfig class, then add PasswordHasher as below
public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store) { PasswordHasher = new CustomPasswordHasher(); }
VIDEO TUTORIALS
- ASP.NET MVC: Free Responsive Templates
- ASP.NET MVC: Implement Password Reset with ASP NET Identity
- ASP.NET MVC: Getting Started
- ASP.NET MVC: Create Custom Routes
- ASP.NET MVC: Create Login Form
- ASP.NET MVC: Login with Google Account
- ASP.NET MVC: Custom properties for IdentityUser
- ASP.NET MVC: Performance Optimization with Bundling and Minification
Categories
Popular Posts
How to implement Jint in C#
09/14/2024
How to Download Chromedriver for Selenium
09/14/2024
C# Tutorial
07/20/2024