Author Topic: VB 2012 Login Validation question [OPEN]  (Read 8324 times)

0 Members and 1 Guest are viewing this topic.

Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
VB 2012 Login Validation question [OPEN]
« on: January 18, 2013, 12:57:41 am »
My problem is with the checking of the username and password against a mysql database, I'm not sure how I would go about doing it. I have searched google but haven't been able to find anything I can understand. Don't give me the answer, just help me out. I am trying to learn.
Code: [Select]
Imports System.Data.SqlClient
Imports System.Data.Sql

Public Class LoginForm1


    Private Sub OK_Click() Handles OK.Click
        Dim Selection() As String = {"SELECT * FROM `users` WHERE `username` = `" + TxtUsername.Text.ToString() + "` AND `password` = `" + TxtPassword.Text.ToString() + "`;"}
        MySql("server=;Port=; user id: password: database=", Selection)
       
            If ???.HasRows = 0 Then
            MsgBox("Bad Login")
        Else
            Form1.Show()
            Application.ExitThread()
        End If
    End Sub

    Private Sub Cancel_Click() Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm1_Load() Handles MyBase.Load

    End Sub

    Private Sub LogoPictureBox_Click() Handles LogoPictureBox.Click

    End Sub

    Private Sub MySql(ByVal ConnectionString As String, ByVal query_array() As String)
        Try
            Using MySqlConnection As New SqlConnection(ConnectionString.ToString())
                For i = 0 To query_array.Length Step 1
                    Dim MySqlCommand As New SqlCommand(query_array(i), MySqlConnection)
                    MySqlCommand.Connection.Open()
                    MySqlCommand.ExecuteNonQuery()

                Next
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Class


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: VB 2012 Login Validation question [OPEN]
« Reply #1 on: January 18, 2013, 08:55:25 am »
Your SQL looks wrong. Comparison in SQL is the same as anywhere - you need to use ==. Now you just have 1 =.

Also doesn't VB have some string formation methods? combining with +'s looks ugly.
« Last Edit: January 18, 2013, 08:56:23 am by Kulverstukas »