Imports MySql.Data.MySqlClient
Public Class login
Dim MySqlConnection As MySqlConnection
Dim mysqlcon As New MySqlConnection("SERVER=;USERID=;PASSWORD=;DATABASE=;Character Set=utf8;")
Dim mysqlcmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Dim dt As New DataTable
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = "server=; user id=; password=; database=; Pooling=false"
Try
MySqlConnection.Open()
'MessageBox.Show("Connection to Database has been opened.")
Catch myerror As MySqlException
MsgBox("[Server Error]ติดต่อฐานข้อมูลไม่ได้ !: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT * FROM user WHERE username = '" & username.Text & "' AND password = '" & password.Text & "';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquary
myadapter.SelectCommand = command
Dim mydata As MySqlDataReader
mydata = command.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("[Warning]ไอดี/พาสเวิร์ด ไม่ถูกต้อง !", MsgBoxStyle.Critical, "Login Failed")
Button1.Enabled = True
Else
CreateObject("WScript.Shell").Popup("<เข้าสู่ระบบสำเร็จ> User : " + username.Text + " <ข้อความนี้จะหายไปใน 1วินาที>", 1, "Login Successful")
Form11.Show()
Me.Close()
End If
End Sub
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub password_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles password.KeyDown
If e.KeyCode = Keys.Enter Then
Button1.PerformClick()
End If
End Sub
Private Sub username_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles username.KeyDown
If e.KeyCode = Keys.Enter Then
Button1.PerformClick()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
username.Text = ""
password.Text = ""
username.Focus()
End Sub
End Class
อันนี้คือ code ที่ใช้ login ที่เชื่อมต่อโดยตรงกับ mysql ครับ
รบกวนทีครับขอบคุณครับ
Tag : .NET, MySQL, VB.NET, Windows, Linux, Web Hosting
Date :
2016-04-07 09:04:00
By :
wanlop8822
View :
1485
Reply :
3
No. 1
Guest
Quote:
เนื่องจากเห็นเขาบอกกันว่าถ้า
เชื่อมต่อ mysql โดยตรงจาก vb.net จะ protect ยังไงก็โดนเจาะแน่นอน
เขานี่ใครเหรอ
ใช้ vb.net ต่อไปแหละ
เราว่า php นี่เน่ากว่า vb.net อีกนะ
แต่แนะนำให้ใช้ salt เพราะเค็มแต่ดี
Date :
2016-04-07 10:13:44
By :
ห้ามตอบเกินวันละ 2 กระทู้
No. 2
Guest
ใช้ tools protect ดีๆ เขียน code เข้ารหัส server ไว้
ยังไงมันก็เจาะได้แค่โปรเจ็ค เข้าถึง server ยาก
ยกเว้นแต่คุณเขียนง่ายๆให้เขาเจาะง่ายๆ