本文介绍了使用VB在LDAP中进行用户验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好!
我想用vb创建代码以连接到LDAP并检索特定的用户名/密码或特定的用户验证.
我是新手,所以任何解释过的代码示例都将非常有用!
Hello!
I want to vb create code to connect to an LDAP and retrieve an specific user/password or specific user validation.
Im new, so any explained code example(s) would be very useful! Thanks!
推荐答案
using System.Security.Principal;
private void GetUserName()
{
WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal user = new WindowsPrincipal(ident);
string username = StripDomainFromUserName(user.Identity.Name);
using (DirectoryEntry de = new DirectoryEntry("LDAP://" + StripDomain(user.Identity.Name)))
{
using (DirectorySearcher adSearch = new DirectorySearcher(de))
{
adSearch.Filter = "(sAMAccountName=" + username + ")";
SearchResult adSearchResult = adSearch.FindOne();
UserCredentials.CommitID = username;
UserCredentials.UserName = StripLoggedUserName(adSearchResult.Path);
UserCredentials.LoginUserName = StripLoggedUserName(adSearchResult.Path);
UserCredentials.LoginUserCommitID = username;
}
}
}
这篇关于使用VB在LDAP中进行用户验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!