当前位置: 首页 > 知识库问答 >
问题:

使用ldap身份验证的MS Access 2010

罗和煦
2023-03-14

我正在尝试在ms access 2010中使用用户名和密码进行ldap身份验证。我似乎无法理解这一点,并在网上尝试了不同的代码,但似乎都不起作用。有人能帮忙吗?

以下是我从这里学到的

Function CheckUser(username As String, passwd As String, Level As Integer) As Boolean

    On Error GoTo LDAP_Error

    username = "sharifu"
    passwd = "xxx"

    Const ADS_SCOPE_SUBTREE = 2

    Dim LDAPPath As String
    LDAPPath = "LDAP://172.16.0.12/OU=Sites;DC=domain;DC=com"

    Dim conn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset

    Set conn = New ADODB.Connection
    Set cmd = New ADODB.Command
    conn.Provider = "ADsDSOObject"

    conn.Properties("User ID") = "domain\" & username
    conn.Properties("Password") = "" & passwd
    conn.Properties("Encrypt Password") = True
    'conn.Properties("ADSI Flag") = 3

    conn.Open "Active Directory Provider"
    Set cmd.ActiveConnection = conn

    cmd.Properties("Page Size") = 1000
    cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE


    cmd.CommandText = _
    "SELECT Name FROM '" & LDAPPath & "' WHERE " & "objectCategory='user'"

    Set rs = cmd.Execute

    rs.Close
    conn.Close

    CheckUser = True
    Exit Function

LDAP_Error:

    If Err.Number = -2147217911 Then

    MsgBox "Incorrect PeopleSoftID or Password!", vbExclamation, "HILDA"

    Else

    MsgBox "Error : " & Err.Description & " " & Err.Number, vbExclamation, "HILDA"

    End If
    CheckUser = False

    conn.Close


End Function

我收到的错误是

“错误:服务器无法运行。-2147217865”

更改为ip地址立即获取以下错误

方法'ActiveConnection'的对象'_Command'失败,但它可能来自其他地方在我的代码.我将如何检查,如果ldap是成功的?

共有2个答案

濮宇定
2023-03-14

为理解此代码和正确运行,进行少量更改和解释:

  1. 添加了检查数据库中是否存在该用户。
  2. 将LDAP路径中的“OU=Sites”更改为“CN=Users”

LDAPPath="LDAP://替换为IP或DNS名称/CN=用户;DC=替换为不带. com的域名;DC=替换为com、net或根节点名称"

完整的例子:

LDAPPath = "LDAP://200.201.1.1/CN=Users;DC=google;DC=com"

或者

LDAPPath = "LDAP://ldap.google.com/CN=Users;DC=google;DC=com"

conn.Properties(“用户ID”)=“ggle”

最后,这是完整的代码:

    Function ldapAuth(userName As String, passwd As String, level As Integer) As Boolean

    On Error GoTo LDAP_Error
    ldapAuth = False

    If Not IsNull(userName) And Not IsNull(passwd) Then

    'Check if the user exist in DB
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim qdf As QueryDef
    Dim strSQL As String

    Set dbs = CurrentDb

    strSelect = "SELECT *"
    strFrom = " FROM employee"
    strWhere = " WHERE user_name = '" & userName & "';"
    strSQL = strSelect & strFrom & strWhere

    Debug.Print strSQL

    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
    'If the recordset is empty, exit.
    If rst.EOF Then
        MsgBox "The user not exist in the DataBase!!!"
    Else
        'Check user with LDAP
        Const ADS_SCOPE_SUBTREE = 2

        Dim LDAPPath As String
        LDAPPath = "LDAP://ldap.google.com/CN=Users;DC=google;DC=com"

        Dim conn As ADODB.Connection
        Dim cmd As ADODB.Command
        Dim rs As ADODB.Recordset

        Set conn = New ADODB.Connection
        Set cmd = New ADODB.Command
        conn.Provider = "ADsDSOObject"
        conn.Properties("User ID") = "ggle\" & userName
        conn.Properties("Password") = "" & passwd
        conn.Properties("Encrypt Password") = True
        'conn.Properties("ADSI Flag") = 3
        conn.Open "Active Directory Provider"

        Set cmd.ActiveConnection = conn
        cmd.Properties("Page Size") = 1000
        cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
        cmd.CommandText = "SELECT Name FROM '" & LDAPPath & "' WHERE " & "objectCategory='user'"

        Set rs = cmd.Execute
        rs.Close
        conn.Close

        'Set userId and Role Globally
        employeeId = rst![id]
        employeeType = rst![employee_type]
        TempVars.Add "employeeId", employeeId
        TempVars.Add "employeeType", employeeType

        'Log user login and role
        Debug.Print "User login: " & TempVars!employeeId
        Debug.Print "User Role: " & TempVars!employeeType

        ldapAuth = True

        rst.Close

      End If

    End If

    Exit Function

    LDAP_Error:

    If Err.Number = -2147217911 Then
    'MsgBox "Incorrect User or Password!", vbExclamation, "LDAP Authentication"
    Else
    MsgBox "Error : " & Err.Description & " " & Err.Number, vbExclamation, "LDAP Authentication"
    End If

    conn.Close

    End Function

尉迟宣
2023-03-14

我有固定的问题。

Function CheckUser(UserName As String, passwd As String, Level As Integer) As Boolean

    On Error GoTo LDAP_Error

    Const ADS_SCOPE_SUBTREE = 2

    Dim LDAPPath As String
    LDAPPath = "LDAP://akutan.country.domain.com/OU=Sites;DC=domain;DC=com"

    Dim conn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset

    Set conn = New ADODB.Connection
    Set cmd = New ADODB.Command
    conn.Provider = "ADsDSOObject"
    conn.Properties("User ID") = "xxx\" & UserName
    conn.Properties("Password") = "" & passwd
    conn.Properties("Encrypt Password") = True
    'conn.Properties("ADSI Flag") = 3
    conn.Open "Active Directory Provider"

    Set cmd.ActiveConnection = conn
    cmd.Properties("Page Size") = 1000
    cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    cmd.CommandText = "SELECT Name FROM '" & LDAPPath & "' WHERE " & "objectCategory='user'"

    Set rs = cmd.Execute
    rs.Close
    conn.Close

    CheckUser = True
    [TempVars]![CurrentUser] = UserName
    Call LogUser([TempVars]![CurrentUser], "Logon")
    Exit Function

LDAP_Error:

    If Err.Number = -2147217911 Then
        MsgBox "Incorrect PeopleSoftID or Password!", vbExclamation, "LDAP Authentication"
    Else
        MsgBox "Error : " & Err.Description & " " & Err.Number, vbExclamation, "LDAP Authentication"
    End If

    CheckUser = False
    conn.Close

End Function
 类似资料:
  • 我有一个asp。net(C#)设置为使用LDAP进行身份验证。一切正常,我可以和我们目录中的任何用户一起登录。问题是,我需要将某些页面限制为特定组中的人。我正在使用登录查看帐户文件夹的方法。 我的网站设计很简单,它有三个页面,一个供所有人查看(账户文件夹之外),另外两个需要身份验证。我希望一个组可以访问两个网页,另一个组只能访问其中一个网页。 我试过: 但不管我的用户不在该组中。我有一个LDAP浏

  • 我已经创建了一个Restful应用编程接口。我在这里使用LDAP身份验证。我们公司有一个LDAP目录服务器,我在我的中使用下面的方法。 这是我的LDAP身份验证方法,我将此方法用作服务层中的实用程序。 这是我的服务层类,我将实用程序类作为一种注入,可以用于身份验证方法。当我以swagger或postman用户名和密码发送请求时,给定来自请求的值,我会将它们保存到表的数据库中。但在坚持之前,身份验证

  • 我使用Presto Cli测试ldap,下面是以下命令: 它不要求密码,我能够连接到Presto集群,并能够运行查询。为什么LDAP身份验证对此没有任何帮助?

  • 我正在尝试使用passport ldapauth npm验证openLDAP用户名和密码。在执行下面的代码时,我总是收到错误消息:“缺少凭据”。请帮助我我的代码有什么问题。 有关更多详细信息,请参阅此badRequestMessage flash消息以查找缺少的用户名/密码(默认值:“缺少凭据”)

  • 我需要连接到LDAP服务器,但出现以下错误: javax。命名。AuthenticationException:[LDAP:错误代码49-80090308:LDAPPER:DSID-0C09034,注释:AcceptSecurityContext错误,数据525,向量 用户名和密码正确,我尝试设置相同的用户并传入另一个用编写的应用程序。NET,它在那里工作,但在Java中,我收到了错误消息。 我的

  • 我已经安装了OpenLDAP服务器。 如何在LDAP服务器中添加用户(条目)?以及如何打开该服务器的命令窗口,以便在其上运行ldap命令: :我的要求是:在我的应用程序中,我想对Openldap服务器中添加的用户进行身份验证,但我只能在windows os上安装Openldap服务器,但如何添加用户我无法获得方法。在Windows7操作系统上安装openLDAP whic时添加用户的方法是什么?这