[Request] vb.net md5 + salt login menu

User Tag List

Results 1 to 1 of 1
  1. #1
    2dgreengiant's Avatar ★ Elder ★


    Reputation
    1192
    Join Date
    Feb 2007
    Posts
    7,129
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Request] vb.net md5 + salt login

    Hey guys,

    Basically I am making a login thing in visual basic. I can get it to hash the password via MD5 then check it with the database I have etc etc then to login.

    However the passwords stored in the database are MD5 + salt. I have the salt but they are different for every user but I can get the salt from the db using
    SQL and such.

    Problem is I cant get it to work with MD5 + salt. MD5 on its own works fine but with the salt i fail

    Heres the code:

    Code:
    Imports MySql.Data.MySqlClient
    Imports System.Data
    Imports MySql.Data
    Imports MySql
    Imports System.Data.SqlClient
    Imports System.Text
    Imports System.Security.Cryptography
    
    
    Public Class LoginForm1
    
        Function getMD5Salt(ByVal strToHash As String) As String
    
            Dim conn As MySqlConnection
            conn = New MySqlConnection()
            conn.ConnectionString = "server=123.456.789.0;user id=2dlolgiants; password=mmownedisawesome101010; database=2dsdatabaseofawesome"
            Try
                conn.Open()
            Catch myerror As MySqlException
                MessageBox.Show("Error Connecting to Database: " & myerror.Message)
            End Try
    
            Dim strText As String = "SELECT userpass FROM isc_users WHERE userpass='"
            Dim salt As String = "SELECT salt FROM users Where username='" & UsernameTextBox.Text
            Dim bytHashedData As Byte()
            Dim encoder As New UTF8Encoding()
            Dim md5Hasher As New MD5CryptoServiceProvider
    
            Dim passwordBytes As Byte() = encoder.GetBytes(strText)
            Dim saltBytes As Byte() = encoder.GetBytes(salt)
    
            Dim passwordAndSaltBytes As Byte() = _
            New Byte(passwordBytes.Length + saltBytes.Length - 1) {}
    
            For i As Integer = 0 To passwordBytes.Length - 1
                passwordAndSaltBytes(i) = passwordBytes(i)
            Next
    
            For i As Integer = 0 To saltBytes.Length - 1
                passwordAndSaltBytes(i + passwordBytes.Length) = saltBytes(i)
            Next
    
            bytHashedData = md5Hasher.ComputeHash(passwordAndSaltBytes)
    
            Dim hashValue As String
            hashValue = Convert.ToBase64String(bytHashedData)
    
            Return hashValue
    
        End Function
    
    
        Function getMD5Hash(ByVal strToHash As String) As String
    
            Dim md5Obj As New MD5CryptoServiceProvider
    
            Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)
            bytesToHash = md5Obj.ComputeHash(bytesToHash)
            Dim strResult As String = ""
            For Each b As Byte In bytesToHash
                strResult += b.ToString("x2")
            Next
            Return strResult
    
        End Function
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            Dim conn As MySqlConnection
            conn = New MySqlConnection()
            conn.ConnectionString = "server=123.456.789.0;user id=2dlolgiants; password=mmownedisawesome101010; database=2dsdatabaseofawesome"
            Try
                conn.Open()
            Catch myerror As MySqlException
                MessageBox.Show("Error Connecting to Database: " & myerror.Message)
            End Try
            Dim myAdapter As New MySqlDataAdapter
            Dim salt As String = "SELECT salt FROM isc_users Where username='" & UsernameTextBox.Text
            Dim sqlquery = "SELECT username, userpass FROM users Where username='" & UsernameTextBox.Text & "' and userpass='" & getMD5Salt(PasswordTextBox.Text) & "'"
            Dim myCommand As New MySqlCommand()
            myCommand.Connection = conn
            myCommand.CommandText = sqlquery
            myAdapter.SelectCommand = myCommand
            Dim myData As MySqlDataReader
            myData = myCommand.ExecuteReader()
            If myData.HasRows = 0 Then
                MessageBox.Show("Invalid Login Details", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                Dim frm1 = New Form1
                Form1.Show()
                Me.Visible = False
            End If
        End Sub
    
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
            Me.Close()
        End Sub
    
        Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub UsernameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameLabel.Click
    
        End Sub
    
        Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameTextBox.TextChanged
    
        End Sub
    End Class

    Any help at all is appreciated
    If you need me you have my skype, if you don't have my skype then you don't need me.

    [Request] vb.net md5 + salt login

Similar Threads

  1. [Buying] Requesting Battle.net namechange
    By stickman901 in forum World of Warcraft Buy Sell Trade
    Replies: 25
    Last Post: 09-13-2012, 06:37 AM
  2. [Request] VB.NET 2008 Voice Chat
    By EmiloZ in forum Programming
    Replies: 14
    Last Post: 04-11-2012, 09:32 AM
  3. [REQUEST] Battle.net Store Email (30 days gameplay)
    By Dirtyangel in forum World of Warcraft General
    Replies: 1
    Last Post: 03-13-2011, 06:12 PM
  4. [Request] B.net account
    By Sonic Waffle in forum Community Chat
    Replies: 5
    Last Post: 04-17-2010, 01:34 AM
  5. [REQUEST] Theh4x.net Logo
    By Nolixz in forum Art & Graphic Design
    Replies: 0
    Last Post: 07-03-2008, 12:57 PM
All times are GMT -5. The time now is 02:49 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search