• 验证域账户的用户名和密码


    //验证需要的方法。

    public static bool IsAuthenticated(string domain, string username, string pwd)
        {
            string strPath = "LDAP://OU=People,DC=RCOMM,DC=local";
            String domainAndUsername = domain + @"\" + username;
            DirectoryEntry entry = new DirectoryEntry(strPath, domainAndUsername, pwd);

            try
            {    //Bind to the native AdsObject to force authentication.           
                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;
                }

                //Update the new path to the user in the directory.
                strPath = result.Path;
                //_filterAttribute = (String)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                //throw new Exception("Error authenticating user. " + ex.Message);
                return false;
            }

            return true;
        }

     

    //调用

    if (LoginLayer.IsAuthenticated("kefeng.rcomm.local", "someguy", "admin"))
            {
                Response.Write("验证成功!");
            }
            else
            {
                Response.Write("验证失败!");
            }

  • 相关阅读:
    程序员开发工作之算法和架构
    iOS开发学习概述及知识整理
    git基本技巧及进阶
    使用命令行工具运行Xcode 7 UI Tests
    技巧集锦2
    Xcode开发小问题集锦
    Xcode 7如何 免费 真机调试iOS应用
    常用shell script 珍藏
    多线程学习7--CountDownLatch
    学习多线程6---栅栏
  • 原文地址:https://www.cnblogs.com/binaryworms/p/1726961.html
Copyright © 2020-2023  润新知