ASP.NET MVC: Custom Password Hasher with ASP.NET Identity
By FoxLearn 5/29/2017 9:21:44 PM 9.27K
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 Responsive Templates Free Download
- How to upload file in ASP.NET MVC
- How to Create Contact Form Flat Responsive in ASP.NET MVC
- How to check if HttpPostedFileBase is an image
- How to upload Multiple File in ASP.NET MVC
- ASP.NET MVC: Implement Password Reset with ASP NET Identity
- ASP.NET MVC: Getting Started
- ASP.NET MVC: Create Custom Routes
Categories
Popular Posts
Flat Able Admin Dashboard Template
11/18/2024
Regal Admin Dashboard Template
11/18/2024
Plus Admin Dashboard Template
11/18/2024
Admin Tailwind CSS Admin Dashboard Template
11/18/2024