MVP? MVP!

i love C#
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

验证域用户(转)

Posted on 2008-11-19 10:48  renhb  阅读(425)  评论(2)    收藏  举报

public string IsAuthenticated(string UserID, string Password)
        {
            string _path = "LDAP://192.168.10.71/DC=wwsp,DC=com";//"LDAP://172.75.200.1/DC=名字,DC=com,DC=cn";
            string _filterAttribute = null;

            DirectoryEntry entry = new DirectoryEntry(_path, UserID, Password);

            try
            {
                //Bind to the native AdsObject to force authentication.
                DirectorySearcher search = new DirectorySearcher(entry);
                search.Filter = "(SAMAccountName=" + UserID + ")";
                SearchResult result = search.FindOne();

                if (null == result)
                {
                    _filterAttribute = "登录失败: 未知的用户名或错误密码.";
                }
                else
                {
                    _filterAttribute = "true";
                }

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            return _filterAttribute;
        }