importing "stringed" MD5 passwords for membership

M

Mike Tallman

In my current database I have passwords that were hashed and then stored
using the following method:

public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes =
((HashAlgorithm) CryptoConfig.CreateFromName
("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}

I would like to use these passwords with the standard membership provider -
is it possible to convert the passwords into something the standard provider
can understand? I'm thinking if I could reverse the BitConverter ToString()
call I should be able to use the hashedBytes in the database. Does that make
sense, or is it even possible? Thanks
 
D

Dominick Baier [DevelopMentor]

Hi,

the sql membership provider supports salted MD5 hashes (via the hashAlgorithmType
property) - so what *could* work:

revert the string back to a byte array
convert the byte array to a base64 string

use the createUser stored procedure in aspnetdb to add the user (provide
the base64 encoded string as the password) and set an empty salt.

....and tell us if this works :)
 
M

Mike Tallman

Thanks Dominick - it works!

For future reference, here is how I converted the converted the stringed
hash back to a byte array, back to base64 before inserting:

string[] chars = stringedHash.Split('-');
byte[] b = new byte[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
b = (byte)Byte.Parse(chars, NumberStyles.HexNumber);
}
string hash = Convert.ToBase64String(b, Base64FormattingOptions.None);

Thanks again


Dominick Baier said:
Hi,

the sql membership provider supports salted MD5 hashes (via the hashAlgorithmType
property) - so what *could* work:

revert the string back to a byte array
convert the byte array to a base64 string

use the createUser stored procedure in aspnetdb to add the user (provide
the base64 encoded string as the password) and set an empty salt.

....and tell us if this works :)

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com
In my current database I have passwords that were hashed and then
stored using the following method:

public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes =
((HashAlgorithm) CryptoConfig.CreateFromName
("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
I would like to use these passwords with the standard membership
provider - is it possible to convert the passwords into something the
standard provider can understand? I'm thinking if I could reverse the
BitConverter ToString() call I should be able to use the hashedBytes
in the database. Does that make sense, or is it even possible?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top