locked
Login MySQL Md5 Hash RRS feed

  • Question

  • I have managed to create a register form which imports username and password converted into MD5. However, my website which I want my users to be able to use the same username/password for the website and VB application.

    My VB registration form can register users into the database and convert the MD5 of the password. But I can not login to the website with the same credentials which where registered with the application. (I assume my website uses different encryption to MD5.) But even If I could get the below code to work, and login with the converted MD5, would be a start.Because MD5 is used on my VB registration form.

    With the login code below, I cant login on either, the application or the website.Can anyone look at the code for anything i done wrong, or share some info on how to setup login/register forms with MySQL and VB?

    UPDATE: I just noticed that i can login with the login form below, but only if i set the password to clear text in MySQL databse manually. :/

    My website also uses salt table, would this have something to do with it? Please help me with this.

    Imports System.Net
    Imports MySql.Data.MySqlClient
    Imports System.Net.Sockets
    Imports System.Data.SqlClient
    Imports System.Security.Cryptography
    Imports System.Text

    Module md5login

        Public Function MD5StringHashs(ByVal strString As String) As String
            Dim MD5 As New MD5CryptoServiceProvider
            Dim Data As Byte()
            Dim Result As Byte()
            Dim Res As String = ""
            Dim Tmp As String = ""

            Data = Encoding.ASCII.GetBytes(strString)
            Result = MD5.ComputeHash(Data)
            For i As Integer = 0 To Result.Length - 1
                Tmp = Hex(Result(i))
                If Len(Tmp) = 1 Then Tmp = "0" & Tmp
                Res += Tmp
            Next
            Return Res
        End Function

    End Module

    Public Class adminloginForm
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim conn As MySqlConnection

            'Connect to the database using these credentials
            conn = New MySqlConnection
            conn.ConnectionString = "Database=#;" & _
                "Data Source=#;" & _
                "User Id=#;Password=#"

            'Try and connect (conn.open)
            Try
                conn.Open()

            Catch myerror As MySqlException 'If it fails do this... (i.e. no internet connection, etc.)
                MsgBox("Error connecting to server. Check your internet connection.", MsgBoxStyle.Critical)
            End Try


            'MySQL query (where to call for information)
            Dim myAdapter As New MySqlDataAdapter
            Dim password As String = MD5StringHashs(txtpass.Text)
            Dim username As String = txtuser.Text
            'Tell where to find the file with the emails/passes stored
            Dim sqlquery = "SELECT * FROM users WHERE username = '" & txtuser.Text & "' AND password = '" & txtpass.Text & "'"
            Dim myCommand As New MySqlCommand
            myCommand.Connection = conn
            myCommand.CommandText = sqlquery

            'Start query
            myAdapter.SelectCommand = myCommand
            Dim myData As MySqlDataReader
            myData = myCommand.ExecuteReader

            'See if the user exists
            If myData.HasRows = 0 Then
                MsgBox("Invalid username or password.", MsgBoxStyle.Critical)

                'Insert your settings change here. (i.e. My.Settings.LoggedIn = False)

            Else
                MsgBox("Logged in as " & txtuser.Text & ".", MsgBoxStyle.Information)

                'Another settings change: My.Settings.LoggedIn = True
                Server.Show()
                Me.Close() 'close the login form

            End If

        End Sub

        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Register.Click
            RegisterForm.Show()
        End Sub

        Private Sub adminloginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        End Sub

    End Class



    • Edited by DRads Tuesday, June 11, 2013 7:45 PM Update:
    • Moved by Youen Zen Friday, June 21, 2013 9:08 AM
    Tuesday, June 11, 2013 7:24 PM

All replies

  • Is this past Microsoft's publics pay-grade or what.

    Any time I post anywhere online, i either get redirected or a crap reply.

    CAN SOMEONE HELP ME????????????????????

    Wednesday, June 12, 2013 1:22 AM
  • Nevermind.. I think you may post in a wrong forum. for website dev issue, you need to http://forums.asp.net/

    Think again!

    Thursday, June 13, 2013 1:51 AM
  • Probably not with that kind of attitude.
    Friday, June 14, 2013 12:17 AM