MD5 and mysql

sardon

New member
Joined
Jun 7, 2004
Messages
2
Programming Experience
1-3
hello all
not sure if this is the right place for this but ill give it a shot
i am having trouble with md5 hashing. when i hash my password and send it to the database it looks like this

mydatabaseresults.jpg


i wish my password to hash and look like this

database.bmp


im using mysql as my database and i have 3 fields id, user, and pass
i used varchar for pass but im not sure thats the right type
the type i need has to be able to store binary data. heres my code can you point out anything that would make it no be hexadecimal. Is there away to convert my hash to hexadecimal?

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
Dim connectionString As String = "Driver={MySQL ODBC 3.51 Driver};option=4;SERVER=localhost;DATABASE=test;uid=root;pwd=omhoux;"
 
conn = New OdbcConnection(connectionString) 
 
conn.Open()
 
Dim ix As New OdbcCommand("INSERT INTO info(user, pass) VALUES (?,?)", conn)
 
ix.Parameters.Add("@user", OdbcType.VarChar, 255).Value = TextBox1.Text
 
'Encrypt the password
 
Dim md5Hasher As New MD5CryptoServiceProvider
 
Dim hashedBytes As Byte()
 
Dim encoder As New UTF8Encoding
 
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text))
 
ix.Parameters.Add("@pass", OdbcType.Binary, 32).Value = hashedBytes
 
ix.ExecuteNonQuery()
 
conn.Close()
 
Label3.Text = "Success!"
 
TextBox1.Text = ""
 
TextBox2.Text = ""
 
End Sub
 
I would use the build in MD5 function of mySQL (See: http://dev.mysql.com/doc/mysql/en/Encryption_functions.html)

VB.NET:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim connectionString As String = "Driver={MySQL ODBC 3.51 Driver};option=4;SERVER=localhost;DATABASE=test;uid=root;pwd=omhoux;"
   conn = New OdbcConnection(connectionString) 
   conn.Open()
   Dim ix As New OdbcCommand("INSERT INTO info(user, pass) VALUES (?,MD5(?))", conn)
   ix.Parameters.Add("@user", OdbcType.VarChar, 255).Value = TextBox1.Text
   ix.Parameters.Add("@pass", OdbcType.VarChar, 255).Value = TextBox2.Text
   ix.ExecuteNonQuery()
   conn.Close()
   Label3.Text = "Success!"
   TextBox1.Text = ""
   TextBox2.Text = ""
 End Sub

Also, You might want to look into the new Native mySQL connector for .NET at:
http://dev.mysql.com/downloads/connector/net/1.0.html
 
Back
Top