'Using MySQL to Create a Login page in Visual Studio 2010
I am using Visual Studio 2010. I can connect to my MySQL datababse no problem by clicking my login button.
Now I can't figure out how to query the database and check if username and password are correct, and switch to a different form, to display the data loaded from the database.
Can Anyone Help?? Please
I should have posted my Code
This is Login.vb Form
Imports MySql.Data.MySqlClient
Public Class Login
Dim conn As MySqlConnection
Private Sub Login_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login_btn.Click
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;user id=root;password=johnny;database=test"
Try
conn.Open()
If conn.State = ConnectionState.Open Then
connectionstatus.Text = "Connected to Database"
conn.Close()
End If
Catch myerror As MySqlException
connectionstatus.Text = "Unable to Connect to Database"
Finally
conn.Dispose()
End Try
End Sub
End Class
When the login is completed, and username and password are correct, I want it to load Main.vb.
Solution 1:[1]
follow the following article, it explains how to create the login form using mysql and vb http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-3
Solution 2:[2]
What you need is to create a sql command that will find a record in the database table that match the username and password values. So something like
SELECT username, pwd FROM tblUsers WHERE username = @username and pwd = @pwd
You will need to pass the username and password as parameters... do not pass the textbox values directly as you will be open to Sql injection. Execute the command if you get a row then the user exists and their password was correct. You should encrypt the password and only store the encrypted password in the database...
Look for tutorials on how to query database once you connect to it.
Solution 3:[3]
you should never post your mysql information inside of any program - instead try having it connect via php - that way your mysql information is secure
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kamran Ali |
Solution 2 | Mych |
Solution 3 | Just Sayin |