Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > Visual Basic

Visual Basic Visual Basic Discussion

Reply
 
Thread Tools Display Modes
Old 06-29-2006, 06:17 PM   #1 (permalink)
 
Join Date: Jun 2006
Posts: 1
Default Vb.net with Mysql

I've been trying to make my own login/registration system in vb.net, with not too much luck. I got most of my information from www.vbmysql.com, but still haven't been able to complete the login form. I'm trying to connect to the database, users, and the table user. Right now, I'm just trying to retrive the username data and compare it. I'm hopelessly lost now, and on the verge of giving up. Please help me!

Below is a small piece of my code.

Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else
            If pass.Text = "" Then
                MsgBox("Enter a Password!")
            Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            End If
            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user= '" & user.Text & "'"
                conn.Close()
                If sSQL = user.Text Then
                    MsgBox("Success!")
                    work = 1
                End If
            Catch myerror As MySqlException
*** Rest of the code ***
localhost is offline   Reply With Quote
Old 04-12-2008, 01:13 AM   #2 (permalink)
Newbie
 
Vitas's Avatar
 
Join Date: Aug 2007
Posts: 55
Default same problem...

I can't connect to the server that runs uo kr server to mysql... its pain in ass... so just keep trying....
Vitas is offline   Reply With Quote
Old 04-13-2008, 01:33 PM   #3 (permalink)
Ray
Forum Novice
 
Join Date: Jul 2004
Location: Switzerland
Age: 25
Posts: 234
Default

Quote:
Originally Posted by localhost View Post
Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else
            If pass.Text = "" Then
                MsgBox("Enter a Password!")
            Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            End If
            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user= '" & user.Text & "'"
                conn.Close()
                If sSQL = user.Text Then
                    MsgBox("Success!")
                    work = 1
                End If
            Catch myerror As MySqlException
*** Rest of the code ***
This fails, because you haven't executed any query right now.
The assignment of a query to the string sSQL doesn't execute the query, so If sSQL = user.Text Then compares to the SELECT[...] string, which failes unless the user writes exatly this sentence into the textbox.
Please take a look on the MySQLCommand class on how to execute a MySQLReader Query.

something like this: (not tested, written right of my mind)
Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else If pass.Text = "" Then
                MsgBox("Enter a Password!")
        Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user LIKE '" & user.Text & "' AND password = '" & pass.Text & "'"
                Dim command As MySQLCommand = new MySQLCommand( conn, sSQL )
                Dim reader As MySQLReader = command.ExecuteReader()
                While reader.Read()
                    If reader("user").ToString() = user.Text Then
                        MessageBox.Show("Success!") ' do NOT use the Microsoft.VisualBasic namespace, except in legacy code!
                        work = 1
                    End If
                Loop
                conn.Close()
            Catch myerror As MySqlException
       End If
*** Rest of the code ***
Please be aware that this code is very vulnerable to SQL-Injection-attacks, unless you start using parameters (MySQLParameter) correctly. Highly recommended not to use it in production code. But should be quite enough to get you some steps further
Ray is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5