環境:VB6
ADO 2.6或更高
ADO 2.6或更高
Option
Explicit
Const conString = " Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dssopt_sms;Data Source=. "
Dim cn As ADODB.Connection
Private Sub Command1_Click()
Static i As Integer ' 控制登陸的次數
Dim Username As String
Dim Password As String
Dim rs As ADODB.Recordset
Dim be As Boolean
Dim sql As String
i = i + 1
Username = txtUser ‘為了防止注入,要判斷所取的長度、特殊字符替換
Password = txtPassword
' 判斷用戶名是否存在
sql = " select * from 登陸 where 用戶名=' " & Username & " ' "
set rs = new ADODB.Recordset
Call rs.Open(sql, cn, 1 , 1 )
be = (rs.EOF And rs.BOF)
rs.Close
If be Then
If i < 3 Then
MsgBox " 無效的用戶名 " , , " 系統登陸 "
txtUser.SetFocus
SendKeys " {Home}+{end} "
Exit Sub
Else
MsgBox " 多次錯誤登陸,再見! " , , " 系統登陸 "
End
End If
End If
' 判斷密碼是否正確
sql = " select * from 登陸 where 用戶名=' " & Username & " ' and 密碼=' " & Password & " ' "
Call rs.Open(sql, cn, 1 , 1 )
be = (rs.EOF And rs.BOF)
rs.Close
set rs = noting
If Not be Then
' frmPic.Show
' Denglu_name = Username
' Load MDIForm1
MsgBox " Login successful! "
Unload Me
Else
If i < 3 Then
MsgBox " 無效的密碼 " , , " 系統登陸 "
txtPassword.SetFocus
SendKeys " {Home}+{end} "
Else
MsgBox " 多次輸入錯誤,請正確輸入! " , , " 系統登陸 "
End
End If
End If
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open conString
End Sub
Private Sub Form_Unload(Cancel As Integer)
If cn.State <> 0 Then cn.Close
Set cn = Nothing
End Sub
Const conString = " Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dssopt_sms;Data Source=. "
Dim cn As ADODB.Connection
Private Sub Command1_Click()
Static i As Integer ' 控制登陸的次數
Dim Username As String
Dim Password As String
Dim rs As ADODB.Recordset
Dim be As Boolean
Dim sql As String
i = i + 1
Username = txtUser ‘為了防止注入,要判斷所取的長度、特殊字符替換
Password = txtPassword
' 判斷用戶名是否存在
sql = " select * from 登陸 where 用戶名=' " & Username & " ' "
set rs = new ADODB.Recordset
Call rs.Open(sql, cn, 1 , 1 )
be = (rs.EOF And rs.BOF)
rs.Close
If be Then
If i < 3 Then
MsgBox " 無效的用戶名 " , , " 系統登陸 "
txtUser.SetFocus
SendKeys " {Home}+{end} "
Exit Sub
Else
MsgBox " 多次錯誤登陸,再見! " , , " 系統登陸 "
End
End If
End If
' 判斷密碼是否正確
sql = " select * from 登陸 where 用戶名=' " & Username & " ' and 密碼=' " & Password & " ' "
Call rs.Open(sql, cn, 1 , 1 )
be = (rs.EOF And rs.BOF)
rs.Close
set rs = noting
If Not be Then
' frmPic.Show
' Denglu_name = Username
' Load MDIForm1
MsgBox " Login successful! "
Unload Me
Else
If i < 3 Then
MsgBox " 無效的密碼 " , , " 系統登陸 "
txtPassword.SetFocus
SendKeys " {Home}+{end} "
Else
MsgBox " 多次輸入錯誤,請正確輸入! " , , " 系統登陸 "
End
End If
End If
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open conString
End Sub
Private Sub Form_Unload(Cancel As Integer)
If cn.State <> 0 Then cn.Close
Set cn = Nothing
End Sub