• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

asp.net|C#域用户验证

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

           
        }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
【C#基础】继承、封装、多态、接口发布时间:2022-07-14
下一篇:
C#DataSet和DataTable详解发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap