storing asp.net md5 byte array in mysql

storing asp.net md5 byte array in mysql

Postby Digirolomo » Fri 02 Sep 2011 02:45

I am attempting to store an md5 hash of a password in a mysql table.

here's the code to generate the hash:

Dim md5Hasher as New MD5CryptoServiceProvider()

Dim hashedBytes as Byte()
Dim encoder as New UTF8Encoding()

hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(somestring.text))

This produces a byte array. What is the best method of storing this byte array in mysql? Do I have to convert this to a string somehow then save? The perferred solution would be to save this in a binary field type. I'm certain this won't work..

Dim paramPwd as mysqlSqlParameter
paramPwd = New mySqlParameter("@Password", SqlDbType.Binary, 16)
paramPwd.Value = hashedBytes
Digirolomo
 
Posts: 1
Joined: Fri 02 Sep 2011 02:29

Postby Shalex » Thu 08 Sep 2011 13:30

Code: Select all
Dim paramPwd as mysqlSqlParameter
paramPwd = New mySqlParameter("@Password", SqlDbType.Binary, 16)
paramPwd.Value = hashedBytes

This code should work. Be aware that:
1) the name of the MySqlParameter object in the collection of the command should contain the '@' prefix only in the case when parameter in CommandText is used with the '@' prefix: http://www.devart.com/dotconnect/mysql/docs/?Parameters.html;
2) we recommend using MySQL-specific Devart.Data.MySql.MySqlType.Binary instead of System.Data.SqlDbType.Binary.

If this doesn't work, please send us a small test project with the corresponding DDL script to reproduce the issue in our environment.
Shalex
Devart Team
 
Posts: 7338
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for MySQL