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;
                //}

               
            }

  • 相关阅读:
    分页的实现
    调取地图map
    meta标签应用,适应手机屏幕以及关键词、描述的添加
    页面中公共部分的统一调用
    PC端变成手机端的时候,把特效去掉(把canvas标签去掉)
    IIS上绑定域名,发布上线
    动态截取字符串获取当前网页的URL地址
    Vue 打包后报错 Uncaught TypeError: Cannot redefine property: $router
    Vue项目部署到线上页面空白
    让从后台返回的数据在让elementui 的el-select 显示对应的label值而不是value值
  • 原文地址:https://www.cnblogs.com/Anders888/p/2153404.html
Copyright © 2011-2022 走看看