Xavier Peña Xavier Peña - 10 months ago 31
Vb.net Question

MySql's function OLD_PASSWORD in vb.net?

I need this function to create a challenge password to query a third party SOAP provider.

I have found this solution in c#:

Simulating MySql OLD_PASSWORD in .NET or MS SQL?

But translating it to vb.net seems to be way above my level of skill.

My other options are:

  • Create a dll in c# with this function only

  • Query MySQL every time I need to use this function

  • ...

All of them seem bad enough. If anyone could provide any kind of help it would be much appreciated.

Public Function mysql_old_password(sPassword As String) As String

    Dim result As UInt32() = New UInt32(1) {}
    Dim nr As UInt32 = 1345345333, add As UInt32 = 7, nr2 As UInt32 = &H12345671
    Dim tmp As UInt32

    Dim password As Char() = sPassword.ToCharArray()
    Dim i As Int32

    For i = 0 To sPassword.Length - 1
        If password(i) = " "c OrElse password(i) = ControlChars.Tab Then
            Continue For
        End If

        tmp = AscW(password(i))
        nr = nr Xor (((nr And 63) + add) * tmp) + (nr << 8)
        On Error GoTo 0
        nr2 += (nr2 << 8) Xor nr
        add += tmp
    Dim one As UInt32 = 1
    result(0) = nr And ((one << 31) - 1)
    Dim val As UInt32 = ((one << 31) - 1)
    result(1) = nr2 And val
    Dim hash As String = [String].Format("{0:X}{1:X}", result(0), result(1))
    Return hash.ToLower()
End Function