zoukankan      html  css  js  c++  java
  • C# 使用API检查域用户名和密码是否正确

    添加引用:

    using System.Runtime.InteropServices;

        public class VerifyUserByDomain
        {
            private static int LOGon32_LOGon_INTERACTIVE = 2;
            private static int LOGon32_PROVIDER_DEFAULT = 0;
            private static IntPtr tokenHandle = new IntPtr(0);
    
    
            [DllImport("advapi32.dll")]
            private static extern bool LogonUser(string lpszUsername,
                string lpszDomain,
                string lpszPassword,
                int dwLogonType,
                int dwLogonProvider,
                ref IntPtr phToken);
    
    
            public static bool verify(string userName, string pwd, string domain)
            {
                bool boolResult = false;
                tokenHandle = IntPtr.Zero;
                //使用域密码登录
                boolResult = LogonUser(userName, domain, pwd, LOGon32_LOGon_INTERACTIVE, LOGon32_PROVIDER_DEFAULT, ref tokenHandle);
                return boolResult;
            }

     在Windows应用程序中调用方式:

    bool a = Comm.VerifyUserByDomain.verify(Environment.UserName, textBox2.Text.Trim(), Environment.UserDomainName);

  • 相关阅读:
    Unity3D 4.0 界面 基础 入门
    try catch finally 用法
    Mysql表引擎Innodb、MyIsam、Memory
    初步的kudu+impala vs dorisdb vs tidb
    mysql创建类似oracle的dblink
    jedis请求keys超时报错
    php 1223
    php 1214
    php 1216
    php 1222
  • 原文地址:https://www.cnblogs.com/mq0036/p/6397061.html
Copyright © 2011-2022 走看看