域帐号检验zz

http://hi.baidu.com/yanguang1670/blog/item/2ee9db037c31038cd43f7cea.html

 

使用Win32API LogonUser 在C#程序中进行域认证
2008年03月21日 星期五 13:12

使用C#的用户在编写的WinForm程序中,如果需要使用域账号进行认证管理一般需使用Win32API LogonUser()进行。

这里提供一段我使用的完整的验证代码,大家可以根据需要自己进行适当的修改从而实现在WinForm中。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;    //DllImport

namespace WindowsApplicationTest1 ...{     public partial class Form1 : Form     ...{         public Form1()         ...{             InitializeComponent();         }

        private void button1_Click(object sender, EventArgs e)         ...{ const int LOGON32_LOGON_INTERACTIVE = 2; //通过网络验证账户合法性             const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方式                        IntPtr tokenHandle = new IntPtr(0);             tokenHandle = IntPtr.Zero;             /**//*              * textBox2.Text 域 如:officedomain              * textBox1.Text 域帐号 如:administrator              * textBox3.Text 密码 如:123456              */             bool checkok = LogonUser(textBox2.Text, textBox1.Text, textBox3.Text, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);             if(checkok)             ...{                 label1.Text = "欢迎 " + textBox2.Text + " Just YY it.";             }             else             ...{                 label1.Text = "LZ洗洗睡了"; }

        //调用Win32API Import advapi32.dll         [DllImport("advapi32.dll")]         //映射函数LogonUser         private static extern bool LogonUser( string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);     } }

参考资料:

如何验证 VisualBasic.NET 或 Visual Basic 2005 应用程序中 Windows 用户权限 http://support.microsoft.com/kb/841699/zh-cn

LogonUser Function http://msdn2.microsoft.com/en-us/library/aa378184.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值