110,566
社区成员
发帖
与我相关
我的任务
分享
#region IsAuthenticated 判断是否域用户
/// <summary>
/// 判断是否域用户
/// </summary>
/// <param name="username">用户名</param>
/// <param name="pwd">密码</param>
/// <param name="domain">域名</param>
/// <returns></returns>
public bool IsAuthenticated(string username, string pwd, string domain)
{
string ADPath = "LDAP://" + domain;
DirectoryEntry entry = new DirectoryEntry(ADPath,
username, pwd);
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//string str = result.GetDirectoryEntry().Properties["displayName"].Value.ToString();
return true;
}
catch (Exception ex)
{
//AppException oAppException = new AppException("AD Services Login", ex);
return false;
}
}
#endregion
if( IsAuthenticated(this.username.Value, this.userpassword.Value,"xxx.net")==true) 就可以进行检验了