zoukankan      html  css  js  c++  java
  • asp.net|C#域用户验证

      [DllImport("advapi32.dll")]
            private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            public bool ValidateUserAccount(string AstrDomainName, string AstrDomainAccount, string AstrDomainPassword)
            {

                const int LOGON32_LOGON_INTERACTIVE = 2; //通过网络验证账户合法性

                const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方

                IntPtr tokenHandle = new IntPtr(0);
                tokenHandle = IntPtr.Zero;

                string domainName = AstrDomainName; //域 如:officedomain
                string domainAccount = AstrDomainAccount; //域帐号 如:administrator
                string domainPassword = AstrDomainPassword;//密码
                bool checkok = LogonUser(domainAccount, domainName, domainPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);

                return checkok;
            }

     protected void btnSave_Click(object sender, EventArgs e)
            {
                TransFollowing.BLL.Account accountMananger = new TransFollowing.BLL.Account();
                string userName = txtUserName.Text.Trim();
                string passWord = txtPassWord.Text.Trim();

                if (ValidateUserAccount("域用户", txtUserName.Text.Trim(), txtPassWord.Text.Trim()))
                {
                //完全采用域用户来管理
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,                              // version
                userName,          // user name
                DateTime.Now,                   // issue time
                DateTime.Now.AddHours(1),       // expires every hour
                false,                          // don't persist cookie
                ""                         // roles
                );
                FormsAuthentication.SetAuthCookie(userName, false);
                Context.Response.Redirect("~/TransManage/TranManage.aspx");
                }
                //else
                //{
                //    lbError.Visible = true;
                //}

               
            }

  • 相关阅读:
    模拟按键'ESC',解决韩语等输入法对输入框(codemirror)的支持
    grpc的基础知识
    HttpClientFactory 是 HttpClient 的正确使用方式
    Workflow Core + asp.net core 5.0 实现简单审批工作流
    GitHub自动化部署(CD) asp.net core 5.0 项目(免费空间)
    CleanArchitecture Application代码生成插件-让程序员告别CURD Ctrl+C Ctrl+V
    C# 字符串转成JSON对象 反射获取属性值
    java设计模式-状态模式
    2021目前可用的百度网盘不限速下载方法
    docker映射配置文件
  • 原文地址:https://www.cnblogs.com/Anders888/p/2153404.html
Copyright © 2011-2022 走看看