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

               
            }

  • 相关阅读:
    PAT1001
    关于yahoo.com.cn邮箱导入Gmail邮箱验证异常的机制解析及解决办法
    浙大机试感受
    PAT1002
    mysql修改密码后无法登陆问题
    Windows 不能在 本地计算机 启动 OracleDBConsoleorcl
    Deprecated: Function ereg_replace() is deprecated
    PHP中静态方法(static)与非静态方法的使用及区别
    微信小程序开发,weui报“渲染层错误”的解决办法
    Android系统下载管理DownloadManager功能介绍及使用示例
  • 原文地址:https://www.cnblogs.com/Anders888/p/2153404.html
Copyright © 2011-2022 走看看