 |
|
รบกวนขอตัวอย่าง vb.net login mysql โดยเช็คจาก php หน่อยครับ ขอบคุณครับ
พอดีรบกวนขอสคริปโค๊ตตัวอย่าง การ login จาก vb.net โดยให้เช็คจาก php ไป mysql
ถ้าข้อมูลถูกต้องถึงจะ show from ต่อที่ ถ้าผิดก็ไม่ show เนื่องจากเห็นเขาบอกกันว่าถ้า
เชื่อมต่อ mysql โดยตรงจาก vb.net จะ protect ยังไงก็โดนเจาะแน่นอน ก็เลยจะเปลี่ยน
การเชื่อมต่อแบบใหม่โดยอ้อมไปเช็คกับ php แล้ว php เช็คกับ mysql อีกทีอะครับ
แต่ไม่รู้แนวทางเลยครับ เลยรบกวนขอ code ต้นแบบ หรือตัวอย่าง
ทั้ง php code ที่สำหรับเชื่อมต่อ / และ vb.net code สำหรับ login
ขอบคุณล่วงหน้าครับขอบคุณครับ
Code (VB.NET)
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 :
1667 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |