Imports System.Data.OleDb
Imports System.Data
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Onload Event
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim objConn As OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("database/mydatabase.mdb") & ";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM user WHERE Username = '" & Me.txtUsername.Text & "'" & _
" AND Password = '" & Me.txtPassword.Text & "' "
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
If dt.Rows.Count <= 0 Then
Me.lblMsg.Text = "Invalid Username & Password"
Else
Response.Redirect("Wecome.aspx")
End If
End Sub
End Class
Dim sql As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim Oldpass As String = ""
sql = "Select pwd As oldpass from _user where ([user]='" & UsernameTextBox.Text & "')"
cmd = New SqlCommand(sql, mySQLConn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Oldpass = (dr.Item("oldpass"))
End If
dr.Close()
If Oldpass <> PasswordTextBox.Text Then
MessageBox.Show("รหัสผ่านเก่าไม่ถูกต้องค่ะ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
ElseIf newtxtpass.Text <> aginpass.Text Then
MessageBox.Show("กรุณายืนยันรหัสผ่านใหม่ค่ะ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
Else
sql = "Update _user SET pwd='" & newtxtpass.Text & "'"
sql &= " Where (user='" & UsernameTextBox.Text & "')"
Try
With cmd
.CommandType = CommandType.Text
.CommandText = sql
.Connection = mySQLConn
.ExecuteNonQuery()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
End If
MsgBox("เปลี่ยนรหัสผ่านเรียบร้อยแล้วค่ะ")
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objConn As SqlConnection
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "server=(local);uid=sa;pwd=50690000;database=sldsrv"
objConn = New SqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM login WHERE Username = '" & Me.TextBox1.Text & "'" & _
" AND Password = '" & Me.TextBox2.Text & "' "
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
If dt.Rows.Count <= 0 Then
Me.Label1.Text = "Invalid Username & Password"
Else
Response.Redirect("receive.aspx") '<---นี่คือ เว็ปที่เปิดหลังจาก ใส่รหัสถูก
End If
End Sub