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

页面导航:首页 > 软件编程 > vb.net > VB.Net中使用LDAP验证基于微软AD的登录用户

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

来源: 作者: 时间:2016-01-18 16:54 【

[vb]Imports System.DirectoryServicesImports System.Security.Principal[vb]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click D...

[vb]
Imports System.DirectoryServices 
Imports System.Security.Principal 

[vb]
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("}", 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 


摘自 Modest的专栏
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<