I am facing an issue. Previously, we used ASP.NET Core Identity for our login and signup process. However, the requirement has changed, and now we are creating a WebAPI for login and signup using Dapper. The problem is that we have 2,000 old users in our database who are unable to log in because their password hash format is different. I am now using the Bcrypt library for encryption and decryption.
Loading
Naimish MakwanaPosted Aug 27, 2024, 7:11 AM
It sounds like you’re dealing with a challenging migration! The main issue here is the difference in password hashing algorithms between ASP.NET Core Identity and Bcrypt.
ASP.NET Core Identity typically uses the PBKDF2 algorithm for hashing passwords1. On the other hand, Bcrypt has its own format and hashing mechanism2.
To resolve this, you can follow these steps:
Identify the Hashing Algorithm: Confirm the exact hashing algorithm and parameters used by ASP.NET Core Identity. This is usually PBKDF2 with HMAC-SHA2563.
Create a Migration Plan:
Implement the Migration in Code:
Here’s a simplified example in C#:
Thanks
Aman GuptaPosted Aug 27, 2024, 6:08 AM
Hi Sunny,
To address the issue of old users being unable to log in due to a different password hash format, you can follow these steps:
1. Identify Old Hash Format
Determine the format of the old password hashes stored in your database. This could be from a previous encryption library or algorithm.
2. Update Login Process
Modify your WebAPI login process to handle both old and new password hash formats. Here’s a basic approach:
Check Old Hash Format: When a user attempts to log in, first check if their password hash is in the old format.
Verify Old Hash: If it is, use the old hashing algorithm to verify the password. If verification is successful, re-hash the password using Bcrypt and update the user’s record in the database with the new hash.
Example Implementation
Here’s a simplified example using C# and Dapper:
Thanks
Sourabh DhimanPosted Aug 27, 2024, 4:25 AM
Anoop Kumar: May be there's an issue: if the user enters the wrong password, it will encrypt that wrong password and update it in the database.
Anoop Kumar SharmaPosted Aug 26, 2024, 4:05 PM
Hi Sunny,
Below are the two quick options:
1. Migrate the user's credentials data to Bcrypt encryption in one go. For this, you’ll need to identify the hashing algorithm used in ASP.NET Core Identity, decrypt the data, and then re-encrypt it using the Bcrypt library.
2. Add a flag in the database (e.g., IsBcryptUsed) for users who are still using the older hash. During login, you can check whether the user's password is encrypted using the Identity approach. If it is, verify the user with the Identity method, then re-encrypt the password using the Bcrypt library. Make sure to update the flag accordingly.