Discord Server Red Security Twitter Donation to Red Security Red Security Youtube Channel Red Security Tumblr Profile
Login or Register to Hide ads and Accessing all features on the forum

Basic mysql user registration system

1 Replies, 2173 Views

welcome to my basic user registration system
if using cpanel u need to add your ip address to remote hosts
next create new database
now create database user with full perms

now find your database in phpmyadmin click on database name
now click on query button

CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(40) NOT NULL,
`user_username` varchar(40) NOT NULL,
`user_pass` varchar(90) NOT NULL,
`user_type` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB;


After creating a table in the MySQL Database, open the Visual Basic and create a new Windows Form Application. Set up the Form just like this.

   


form1 code:

Imports MySql.Data.MySqlClient

Imports System

Imports System.Security.Cryptography
Imports System.Text

Public Function mysqlconnection() As MySqlConnection

        'return new connection.

        Return New MySqlConnection("server=localhost; user id=root; password=; database=dbuser")



    End Function



    'pass the value of mysqlconnection() as MySQL connection to con.

    Public con As MySqlConnection = mysqlconnection()



    'declaring the variables string

    Public sql As String

    Public result As String



    'declaring the classes

    Dim cmd As New MySqlCommand

    Public dt As New DataTable

    Public da As New MySqlDataAdapter





    Private Sub register(ByVal sqlQuery As String)

        Try

            'OPENING THE CONNECTION

            con.Open()

            'HOLDS THE DATA TO BE EXECUTED

            With cmd

                .Connection = con

                .CommandText = sqlQuery

            End With

            'EXECUTE THE DATA

            result = cmd.ExecuteNonQuery

            'CHECKING IF THE DATA HAS BEEN EXECUTED OR NOT

            If result = 1 Then

                MsgBox("User has been registered.")

            Else

                MsgBox("Failed to register the user.")

            End If

            con.Close()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try
    End Sub


 Public Sub loginUser(ByVal sql As String)

        Try







            'declaring the variable as integer

            Dim maxrow As Integer



            'open the connection

            con.Open()

            'every click the button the dt will set a new datatable so that it will retrieve new data in the table

            dt = New DataTable

            'set a command

            With cmd

                'holds the data 

                .Connection = con

                .CommandText = sql

            End With

            'retriving the data

            da.SelectCommand = cmd

            da.Fill(dt)



            'pass the total value of rows in the table to a variable maxrow

            maxrow = dt.Rows.Count



            'conditioning the total value of rows in the table

            'if the total value of rows in the table is greater than 0 then the result is true

            ' and if not, the result is false

            If maxrow > 0 Then

                'appearing the record of the current row and the current column in the current table.

                MsgBox(dt.Rows(0).Item(1) & " , " & dt.Rows(0).Item(4))

            Else

                'the result is false

                MsgBox("Account does not exist.")



            End If

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

        con.Close()

        da.Dispose()
    End Sub

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

 'put the string value to sql  

        sql = "INSERT INTO `users` (`name`, `username`, `Pass`, `type` ) VALUES ('" _

        & txtname.Text & "','" & txtuser.Text & "','" & txtpass.Text & "','" & cbotype.Text & "')"



        'call your sub name and put the sql in the parameters list.

        register(sql)


    End Sub

Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click

 'put the string value to sql  

        sql = "SELECT * from users WHERE username = '" & username.Text & "' and Pass = '" & password.Text & "'"



        'call your sub name and put the sql in the parameters list.

        loginUser(sql)


    End Sub
End Class

'now name the textBoxes for register user

textbox1 = txtname
textbox2 =  txtuser
textbox3 = txtpass

' now name the textbox for login
textbox4 = username
textbox5 = password

'proof that it works keep in mind this version does not have encryption

mysql>  SELECT *  FROM  `users`  LIMIT 0 , 30;
+----+------+----------+----------------------------------+---------------+
| id | name | username | Pass                             | type          |
+----+------+----------+----------------------------------+---------------+
| 11 | red  | redsec   | 90C7CF8F283BF0126317C0357F689C82 | Administrator |
| 12 | red1 | redsec1  | F2AA9C917244CBF0AED0732AEBF4ECF7 | Administrator |
| 13 | red2 | redsec2  | 36EB4E7CE4433AA9D02835948C016F2B | Administrator |
+----+------+----------+----------------------------------+---------------+
3 rows in set (0.00 sec)
(This post was last modified: 07-05-2017, 02:37 AM by viruss.)
Thanks bro I just saw this tut Smile
Rs
* Thankful to Allah *
Kurdy

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic username and pasword login viruss 3 3,137 07-04-2017, 01:31 PM
Last Post: Mr.Kurd
  Basic vb.net spammer viruss 2 4,087 06-18-2017, 11:46 AM
Last Post: viruss



Users browsing this thread: 1 Guest(s)