World of Warcraft registration account using VB.NET with SRP6

57 Views Asked by At

Hello i'm having trouble with creating account from vb.net application to database. I have make the stuff, it add in database the record, but when i try login ingame not recognize the password. So it means that encryption is wrong somewhere. As i know storing in db is like Upper User + Upper Password. Maybe someone can help me to fix it.

Public Sub RegisterUser()
        Dim conStr = "Server=" + Data.Settings.MySQLServerHost + ";Uid=" + Data.Settings.MySQLServerUser + ";Database=" + Data.Settings.AuthDatabase + ";Port=" + Data.Settings.MySQLServerPort + ";Pwd=" + Data.Settings.MySQLServerPassword + ";"
        Dim salt(31) As Byte
        Using rng As New RNGCryptoServiceProvider()
            rng.GetBytes(salt)
        End Using
        ' calculate verifier using this salt
        Dim verifier As Byte() = SRP6.CalculateSRP6Verifier(TextAccountCreateName.Text, TextAccountPasswordCreate.Text, salt)
        ' done - this is what you put in the account table!
        Dim newSalt As Byte() = salt
        Dim newVerifier As Byte() = verifier
        'Dim result As Integer = $mysqli_auth->query("INSERT INTO account (username, email, salt, verifier) VALUES ('$username', '$email', '$newSalt', '$newVerifier')")
        Try
            Using conn As New MySqlConnection(conStr)
                Using cmd As New MySqlCommand()
                    cmd.Connection = conn
                    Select Case Data.Settings.SelectedCore
                        Case Cores.AzerothCore
                            cmd.CommandText = "INSERT INTO account (username, email, salt, verifier) VALUES (@user,@ema,@pass,@verif)"
                            cmd.Parameters.AddWithValue("@user", TextAccountCreateName.Text)
                            cmd.Parameters.AddWithValue("@ema", TextAccountEmailCreate.Text)
                            cmd.Parameters.AddWithValue("@verif", newVerifier)
                            If Data.Settings.EnableDBEncrypt And Data.Settings.DatabaseEncryption >= 1 Then
                                cmd.Parameters.AddWithValue("@pass", newSalt)
                            Else
                                cmd.Parameters.AddWithValue("@pass", TextAccountPasswordCreate.Text)
                            End If
                        Case Else
                            Exit Sub
                    End Select
                    conn.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

And here is my class

Imports System.Security.Cryptography
Imports System.Numerics
Public Class SRP6
    Public Shared Function CalculateSRP6Verifier(ByVal username As String, ByVal password As String, ByVal salt As Byte()) As Byte()
        ' algorithm constants
        Dim g As BigInteger = BigInteger.Parse("7")
        Dim N As BigInteger = BigInteger.Parse("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7", Globalization.NumberStyles.HexNumber)
        ' calculate first hash
        Dim h1 As Byte() = SHA1.Create().ComputeHash(Text.Encoding.UTF8.GetBytes(username.ToUpper() & ":" & password.ToUpper()))
        ' calculate second hash
        Dim h2 As Byte() = SHA1.Create().ComputeHash(salt.Concat(h1).ToArray())
        ' convert to integer (little-endian)
        Dim h2Int As New BigInteger(h2.Reverse().ToArray())
        ' g^h2 mod N
        Dim verifier As BigInteger = BigInteger.ModPow(g, h2Int, N)
        ' convert back to a byte array (little-endian)
        Dim verifierBytes As Byte() = verifier.ToByteArray().Reverse().ToArray()
        ' pad to 32 bytes, remember that zeros go on the end in little-endian!
        Array.Resize(verifierBytes, 32)
        ' done!
        Return verifierBytes
    End Function
End Class

It stores in database the record, but when try login ingame it shows wrong information for password.

0

There are 0 best solutions below