zoukankan      html  css  js  c++  java
  • 验证域账户的用户名和密码

    //验证需要的方法。

    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("验证失败!");
            }

  • 相关阅读:
    pip换国内源
    docker build 的 cache 机制
    jenkins 修改log路径
    lsb_release: command not found 解决
    Linux 添加开机启动项的三种方法
    FAT AP v200R005 配置二层透明模式(web&命令行,开局)
    SharePoint 2010 文档管理系列之星级评论功能
    SharePoint 2010 文档管理之过期归档工具
    SharePoint 2010 文档管理系列之文档搜索
    SharePoint 2010 文档管理系列之准备篇
  • 原文地址:https://www.cnblogs.com/binaryworms/p/1726961.html
Copyright © 2011-2022 走看看