I’m updating an old ASP/MySql webapp to ASP.NET/MS SQL.
We would like to keep the logins from the old website working in the new app.
Unfortunately the passwords were stored in the MySql DB using MySql’s password() function.
Is it possible to simulate MySql’s password() function in either .NET or
MS SQL?
Any help/links are appreciated.
According to MySQL documentation, the algorithm is a double SHA1 hash. When examining the MySQL source code, you find a function called make_scrambled_password() in libmysql/password.c. The function is defined as follows:
Given this method, you can create a .NET counterpart that basically does the same thing. Here’s what I’ve come up with. When I run SELECT PASSWORD(‘test’); against my local copy of MySQL, the value returned is:
*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29According to the source code (again in password.c), the beginning asterisk indicates that this is the post-MySQL 4.1 method of encrypting the password. When I emulate the functionality in VB.Net for example, this is what I come up with:
Keep in mind that SHA1Managed() is in the System.Security.Cryptography namespace. This method returns the same output as the PASSWORD() call in MySQL. I hope this helps for you.
Edit: Here’s the same code in C#