加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB.Net中使用LDAP验证基于微软AD的登录用户

发布时间:2020-12-16 22:32:27 所属栏目:大数据 来源:网络整理
导读:Imports System.DirectoryServicesImports System.Security.Principal Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim r As Boolean = GetUserSID("MyADServer","username","password").
Imports System.DirectoryServices
Imports System.Security.Principal

    Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
        Dim r As Boolean = GetUserSID("MyADServer","username","password").Length > 0
        MsgBox(r)
    End Sub

    Public Shared Function GetUserSID(ByVal ldapServer As String,ByVal userName As String,ByVal password As String) As String
        Dim strPath As String
        If ldapServer.IndexOf("."c) <> -1 Then
            strPath = String.Format("LDAP://{0}",ldapServer)
        Else
            strPath = String.Format("WinNT://{0}/{1},user",ldapServer,userName)
        End If
        Dim entry As New DirectoryEntry(strPath,userName,password)
        Try
            Return New SecurityIdentifier(entry.Properties("objectSid").Value,0).Value
        Catch
            Return ""
        Finally
            entry.Dispose()
        End Try
    End Function

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读