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

               
            }

  • 相关阅读:
    js中return、return true、return false的区别
    flask,中间键
    flask,自定义中间件
    flask,闪现
    flask获取前端发送过来的数据
    flask中的如何将后端写前端的代码设置session
    flask中的正则匹配
    flask中的四剑客 及其他参数
    支付宝接口
    flasks框架简介
  • 原文地址:https://www.cnblogs.com/Anders888/p/2153404.html
Copyright © 2011-2022 走看看