Results 1 to 3 of 3
  1. #1
    cosconub's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    in the programming section MPGH Cash: $90,000,000,000
    Posts
    372
    Reputation
    -4
    Thanks
    39
    My Mood
    Psychedelic

    [help]MySql login system [help]

    how would i use this

    https://www.mpgh.me/forum/33-visual-b...connector.html

    to make a login system to use mysql


    i have a database / sever

    A man is but the product of his thoughts what he thinks, he becomes.
    ~Mohandas Gandhi


    A Genius is nothing with out an idea, An idea is always an idea even without a genius.
    ~ Immortal

  2. #2
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    [php]'Coded by Blubb1337 from MPGH

    Imports MySql.Data.MySqlClient
    Imports System.Text
    Imports System.Security.Cryptography

    Public Class frmLogin

    'make sure your database allows external access, else it will not work
    'free databases mostly do not allow external access, there are a few which do though
    'the only thing you need to fill in is obviously the server, database username/password/table and the name of the database itself

    Private table As String = "User" 'name of the table
    Private conn As New MySqlConnection("server=;" & "user id=;" & "password=;" & "database=")
    Private reader As MySqlDataReader

    'current database structure:
    'create table `DBName`.`TableName`(
    '`Index` int NOT NULL AUTO_INCREMENT ,
    '`Username` mediumtext ,
    '`Password` mediumtext ,
    '`Email` mediumtext ,
    ' PRIMARY KEY (`Index`)
    ')

    #Region "Functions"

    'the md5 function crypts the password
    'therefore it cannot be uncrypted again

    Public Function MD5StringHash(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 Region

    #Region "Database"

    Private Sub Login()
    cmdLogin.Enabled = False
    cmdRegister.Enabled = False

    Try
    conn.Open()

    Dim strSQL As String = "SELECT * FROM " & table & " WHERE Username='" & txtID.Text & "' AND Password='" & MD5StringHash(txtPW.Text) & "'"

    Dim cmd As New MySqlCommand(strSQL, conn)
    reader = cmd.ExecuteReader

    If CInt(reader.HasRows) <> 0 Then
    Me.Close()
    frmMain.ShowDialog()
    Else
    MsgBox("Access denied.", MsgBoxStyle.Information)
    End If

    reader.Close()

    conn.Close()
    Catch ex As MySqlException
    conn.Close()
    End Try

    cmdRegister.Enabled = True
    cmdLogin.Enabled = True
    End Sub

    Private Sub Register()
    cmdRegister.Enabled = False

    Try
    conn.Open()

    Dim strSQL As String = "INSERT INTO " & table & "(Username,Password,Email) VALUES ('" & txtRegID.Text & "','" & MD5StringHash(txtRegPW.Text) & "','" & txtRegEmail.Text & "')"
    Dim strSQL2 As String = "SELECT * FROM " & table & " WHERE Username='" & txtRegID.Text & "' OR Email='" & txtRegEmail.Text & "'"

    Dim cmd As New MySqlCommand(strSQL, conn)
    Dim cmd2 As New MySqlCommand(strSQL2, conn)

    reader = cmd2.ExecuteReader

    If CInt(reader.HasRows) = 0 Then
    reader.Close()
    cmd.ExecuteNonQuery()

    MsgBox("Successfully created the account " & txtRegID.Text & ".", MsgBoxStyle.Information)
    Else
    reader.Close()
    MsgBox("The username or email already exists.", MsgBoxStyle.Information)
    End If

    conn.Close()
    Catch ex As MySqlException
    conn.Close()
    End Try

    cmdRegister.Enabled = True
    End Sub

    #End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Control.CheckForIllegalCrossThreadCalls = False
    End Sub

    Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    Dim t As New Threading.Thread(AddressOf Login)
    t.Start()
    End Sub

    Private Sub txtID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtID.TextChanged
    My.Setting***** = txtID.Text
    My.Settings.Save()
    My.Settings.Reload()
    End Sub

    Private Sub txtPW_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPW.TextChanged
    My.Settings.pw = txtPW.Text
    My.Settings.Save()
    My.Settings.Reload()
    End Sub

    Private Sub cmdRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRegister.Click
    Dim t As New Threading.Thread(AddressOf Register)
    t.Start()
    End Sub
    End Class [/php]

    Download the full project



  3. The Following 2 Users Say Thank You to Blubb1337 For This Useful Post:

    cosconub (12-29-2010),Lolland (12-29-2010)

  4. #3
    cosconub's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    in the programming section MPGH Cash: $90,000,000,000
    Posts
    372
    Reputation
    -4
    Thanks
    39
    My Mood
    Psychedelic
    thanks bubb i will reply if i have any more questions

    A man is but the product of his thoughts what he thinks, he becomes.
    ~Mohandas Gandhi


    A Genius is nothing with out an idea, An idea is always an idea even without a genius.
    ~ Immortal