'定义数据库对象变量 Dim objCn As New Connection, objRs As New Recordset, strCn As String, strSQL As String
'公用数据库掉用函数 Public Function check_password(ByVal UserName As String, ByVal Password As String) As Byte On Error GoTo gpError '建立数据库连接(局域网中的各个计算机共享的数据库) objCn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=\\" & 127.0.0.1 & "\共享文件夹\data.mdb;" objCn.Open '执行查询命令,获得用户登录口令 strSQL = "Select pasword FROM admin Where user='" & UserName & "'" Set objRs.ActiveConnection = objCn objRs.Open (strSQL) '判断有无查询结果 If objRs.EOF Then check_password = 0 '没有查询结果,表示该用户为非法用户 Else '检查口令是否正确 If Password <> Trim(objRs.Fields("pasword").Value) Then check_password = 1 '口令不正确 Else check_password = 2 '口令正确 End If End If '关闭数据库连接,释放对象 objCn.Close Set objRs = Nothing Set objCn = Nothing Exit Function gpError: MsgBox Err.Description '验证无法正常完成,返回错误代码 check_password = 255 Set objRs = Nothing Set objCn = Nothing End Function
|