Results 1 to 5 of 5
  1. #1
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108

    [Tut]REAL Register/Login - MySQL

    I'm going to show you how to embed a REAL login system using mysql.

    This tutorial is kinda advanced, so take your time

    Needed files for this tutorial:

    - MySQL, I'm using 6.0.10(43,7 mb)
    - MySQL connector(attachment)
    - VB.Net
    - SQLyog - This isn't freeware, you can either get a 30 days trial or get it from a warez site
    I'm not giving you a link though.

    What is SQLyog?

    SQLyog MySQL GUI is the most powerful MySQL manager and admin tool, combining the features of MySQL Query Browser,
    Administrator, phpMyAdmin and other MySQL Front Ends and MySQL GUI tools in a single intuitive interface.
    We are going to use SQLyog to create our database and stuff.

    - Last but not least, a brain - I cannot send you a link, since this is uncrackable, Sorrez.

    Overview:

    1. Setting up MySQL
    2. Creating a database in SQLyog
    3. Starting your project & adding a md5 module
    4. Adding the MySQL Library(.dll)
    5. Register to your database
    6. Create the final login in VB.NET
    7. Read your Login table in VB

    Moving on...

    __________________________________________________ ____________________________________

    1. Setting up MySQL

    Download MySQL and install it.

    I won't show you how to click "Next" on each step =D.

    Afterwards, the MySQL Server Instance Configuration Wizard is started.

    You can always configure your settings by clicking Start > Programs > MySQL > MySQLServer 6.0 > MySQL Server Instance...

    Next > Detailed Configuration > Next



    Selecting the server type:

    You see 3 types of server machines available, since each one has it's own description I do not have to explain it to you.

    Depending on what you are going to do, you may select Developer Machine just to start off.

    > Next

    Selecting the database usage:

    Same as before. This is well described and no need to be explained.

    I'd either use mutlifunctional database or non-transactional database only.

    > Next

    This is kinda obvious, simply browse the folder you want MySQL's datafile settings to be saved to.

    > Next

    Approximate number of concurrent connections:

    Depending on what you are going to do, you may start of with like 20 connections.

    You can still higher it anytime.

    > Next

    Networking Options:

    Enable both and tick the firewall exception. The default port is 3306, you may leave it default.

    > Next

    Default Character Set:

    Not much to say, simply hit...

    > Next

    Windows Options:

    I recommend you to change the service name, otherwise the service might not be startable.

    I myself had the same problem. Simply change the service name to MySQL501 or so and you'll be fine

    You may check the "Include Bin Directory in Windows PATH"-thingy, however this is not really neded.

    > Next

    Security Options:

    Enter a password for your database access. It is recommended to use a 'difficult' password.

    > Next

    Hit execute and see if you get any errors.

    > You're Done =D

    You successfully installed MySQL, took you long enough =D

    __________________________________________________ ____________________________________

    2. Creating a database in SQLyog

    Now, moving on to creating a database with tables, we need to download SQLyog


    After downloading and install the program, start it.

    New Connection... > Enter a Name > Hit OK

    Default host address: localhost
    Default username: root
    Password: The one you entered in the setup
    Default Port: 3306

    Leave the rest by default.



    Hit connect.

    Righ***ick on root@localhost > Create Database



    Name it "User" and hit Create.

    Righ***ick on Tables > Create Table



    Create Table...



    Name it "Login"...Hit OK.

    You are done with creating a database. Now we will have to go into VB .

    __________________________________________________ ____________________________________

    3. Starting your project & adding a md5 module

    Start your a new VB project...



    Drag 1 Button and 3 Textboxes on the form.

    Textbox1 = txtID
    Textbox2 = txtPW
    Textbox3 = txtEmail



    We start off by creating an MD5 Module to actually 'secure' the passwords and not make them readable.

    Solution-Explorer > Your Application > Righ***ick > Add Module > OK

    Paste in the following code:

    Code:
    Imports System.Security.Cryptography
    Imports System.Text
    Module md5
    
    	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 Module


    __________________________________________________ ____________________________________

    4. Adding the MySQL Library(.dll)

    Download the attachment "mysql-connector-net-5.2.6" below.

    Run it & install it.

    Select your installation folder, if you left it default simply leave this default, too.

    In Vb.Net go into the Solution-Explorer again.

    Righ***ick on your application > Add Reference



    In .Net components tab search for MySQL.Data.



    If you cannot find it, you either forgot to install the mysql-connector(attachment) or you forgot to
    restart VB.Net.

    To embed the .dll you will need the following namespace above Form1:

    Code:
    Imports MySql.Data.MySqlClient
    
    Public Class Form1
    
        
    End Class
    __________________________________________________ ____________________________________

    5. Register to your database

    In the next two steps make sure:

    • Your database is named 'user'
    • Your table is named 'login'
    • You have three columns named: 'ID', 'Password', 'Email'


    On button click_event:

    The code is commented.

    Code:
     Dim conn As MySqlConnection
            conn = New MySqlConnection
            conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=YourPW;" & "database=user"
    
            Try
                conn.Open() ' open connection
    
            Catch myerror As MySqlException
                MsgBox("Couldn't connect to the database: " & myerror.Message.ToString)
            End Try
    
            Dim myAdapter As New MySqlDataAdapter
            Dim SQLQuery As String = "SELECT * FROM login WHERE ID='" + txtID.Text + "'" ' A query to see if the user already exists
            Dim myCommand As New MySqlCommand
            myCommand.Connection = conn
            myCommand.CommandText = SQLQuery
    
            myAdapter.SelectCommand = myCommand
            Dim myData As MySqlDataReader
            myData = myCommand.ExecuteReader() ' start query
    
            If myData.HasRows = 0 Then 'if the user doesn't exist yet, start the query
                conn.Close()
                conn.Open()
                Dim registerfinal As New MySqlDataAdapter
                Dim benutzer As String = txtID.Text
                Dim passwort As String = MD5StringHash(txtPW.Text)
                myCommand.CommandText = "INSERT INTO login(ID, Password, Email)" _
                                     & "VALUES('" & benutzer & "','" & passwort & "','" & txtEmail.Text & "')"
                myCommand.ExecuteNonQuery() ' start query and insert values into our "login" table
                MsgBox("The account: " & txtID.Text & " has been created successfully.")
                conn.Close()
            Else
                MsgBox("Account already exists")
            End If


    __________________________________________________ ________________

    6. Create the final login in VB.NET

    Code:
    Dim conn As MySqlConnection
            conn = New MySqlConnection
            conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=YourPW;" & "database=user"  'Server data
    
            Try
                conn.Open() ' open the connection
            Catch myerror As MySqlException
                MsgBox("Couldn't connect to the database: " & myerror.Message.ToString) ' catch the error
            End Try
    
            Dim ID As String = txtID.Text
            Dim PW As String = MD5StringHash(txtPW.Text)
    
            Dim myAdapter As New MySqlDataAdapter
            Dim SQLQuery As String = "SELECT * FROM login WHERE ID='" + Replace(id, " ", "") + "' AND Password='" & Replace(pw, " ", "") & "'" ' Das ist die Abfrage welche Prüft ob der Account existiert.Die txt_benutzer ist die Textbox in der der Benutzername eingeben wird und txt_passwort bekommt das Passwort
            Dim myCommand As New MySqlCommand
            myCommand.Connection = conn
            myCommand.CommandText = SQLQuery
    
            myAdapter.SelectCommand = myCommand
            Dim myData As MySqlDataReader
            myData = myCommand.ExecuteReader() ' start query
            If myData.HasRows Then ' if the pw/id is correct
                MsgBox("Successfully logged in.")
                conn.Close()
                conn.Open()
    
            Else 'Display error
                MsgBox("Wrong ID/PW.")
            End If
    You can sure do everything instead of the MsgBox.

    __________________________________________________ ________________

    7. Read your Login table in VB

    Drag a DataGridView(Toolbox) onto your form.

    Button_event:

    Code:
     Dim conn As MySqlConnection
            conn = New MySqlConnection
            conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=YourPW;" & "database=user"  'login data
    
            Try
                conn.Open() ' open connection
            Catch myerror As MySqlException
                MsgBox("Couldn't connect to the database: " & myerror.Message.ToString) ' catch error
            End Try
    
            Dim myAdapter As New MySqlDataAdapter
            Dim SQLQuery As String = "SELECT * FROM login" ' select everything from login
            Dim da As mysql.Data.MySqlClient.MySqlDataAdapter
            Dim dt As New DataTable
    
            da = New MySqlDataAdapter(SQLQuery, conn)
    
            Try
                da.Fill(dt) 'fill in the data
            Catch myerror As MySqlException 'catch the error if there's one
                MsgBox(myerror.Message.ToString)
            End Try
    
            DataGridView1.DataSource = dt
    __________________________________________________ ________________


    Now you are actually able to create an account/logging in using your VB application.

    I do not recommend this method if you haven't got a RootServer/VServer/Online DB/24/7 running pc.

    There are online databases to connect your VB project with.

    I'm going to search for them and make another tutorial about it

    I do hope you understood everything and enjoyed it.

    Credits:
    Rokky from vb-paradise for most(not everything) of the code
    Me: Writing the whole tutorial(took me some time)

    VirusScan for attachment
    Last edited by Blubb1337; 05-22-2010 at 09:22 AM.



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

    Dead(H)ell (03-17-2013),Erinador (09-29-2010),Hassan (05-22-2010),Jason (05-22-2010),pDevice (01-23-2013),ppl2pass (05-22-2010),R9F6T (07-29-2011),ricardo17089 (05-29-2013),Sixx93 (05-23-2010),sonikboy (10-17-2014),vcinzz (05-03-2012),xoxokkkk (02-01-2014),Zoom (05-22-2010)

  3. #2
    Zoom's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Your going on my 24/7 DDoS hit list.
    Posts
    8,552
    Reputation
    127
    Thanks
    5,970
    My Mood
    Happy
    Gooooooood job!

    Thanks for sharing.
    -Rest in peace leechers-

    Your PM box is 100% full.

  4. #3
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Good Job man.

    Thnx for sharing !!

  5. #4
    EndRiT's Avatar
    Join Date
    Dec 2005
    Gender
    male
    Location
    USSR
    Posts
    12,751
    Reputation
    170
    Thanks
    4,294,967,295
    File approved.

  6. #5
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    very nice tut, ty alot 4 sharing!

Similar Threads

  1. [Release] real? HotAnime Login?
    By GS-HITMAN in forum CrossFire Mods & Rez Modding
    Replies: 38
    Last Post: 05-08-2011, 10:02 AM
  2. [TUT] Easy Login/Register Form [NOOB FRIENDLY]
    By imsocruel in forum Programming Tutorials
    Replies: 8
    Last Post: 11-20-2010, 12:20 AM
  3. [Tutorial] [TUT]How to Login to Gamersfirst using firefox[TUT]
    By xXcOdXx in forum WarRock Discussions
    Replies: 6
    Last Post: 10-01-2010, 07:27 AM
  4. [TUT] How to find real KSSN's to play KWR.
    By Synns in forum WarRock Korea Hacks
    Replies: 12
    Last Post: 02-19-2009, 05:10 PM
  5. tut: way to get real kssn
    By syforce in forum WarRock Korea Hacks
    Replies: 2
    Last Post: 05-28-2007, 06:06 AM