Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Validate NT passwords in c# on windows XP

How to Validate NT passwords in c# on windows XP

Scheduled Pinned Locked Moved C#
tutorialcsharp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zoltix
    wrote on last edited by
    #1

    How to validate user credentials (SSPI)on winNt, win2000,winXp, and without act as part of operating system privilege. Example Bool fctCheckUser(user,password,domain); Return: True is validate, false is not validate I implented that but it don'work under windows xp.. [DllImport("Advapi32.dll")] public static extern long LogonUser(string lpszUserName,string lpszDomain,string lpszPassword,long dwLogonType,long dwLogonProvider,long phToken); const long LOGON32_PROVIDER_DEFAULT= 3; const long LOGON32_LOGON_NETWORK= 0; public Form1() { long ret = LogonUser("ll2","ww_europe","zoaqsdfzsol7",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,ht); MessageBox.Show(ret.ToString(), "test",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } -=zoltx=-

    Richard DeemingR 1 Reply Last reply
    0
    • Z zoltix

      How to validate user credentials (SSPI)on winNt, win2000,winXp, and without act as part of operating system privilege. Example Bool fctCheckUser(user,password,domain); Return: True is validate, false is not validate I implented that but it don'work under windows xp.. [DllImport("Advapi32.dll")] public static extern long LogonUser(string lpszUserName,string lpszDomain,string lpszPassword,long dwLogonType,long dwLogonProvider,long phToken); const long LOGON32_PROVIDER_DEFAULT= 3; const long LOGON32_LOGON_NETWORK= 0; public Form1() { long ret = LogonUser("ll2","ww_europe","zoaqsdfzsol7",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,ht); MessageBox.Show(ret.ToString(), "test",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } -=zoltx=-

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The C++ DWORD type is equivalent to the .NET Int32 type, which is int in C#.

      using System;
      using System.Runtime.InteropServices;

      public class WindowsLogon
      {
      public enum LogonType
      {
      Batch = 4,
      Interactive = 2,
      Network = 3,
      NetworkCleartext = 8,
      NewCredentials = 9,
      Service = 5,
      Unlock = 7,
      }

      public enum LogonProvider
      {
          Default = 0,
          WinNT35 = 1,
          WinNT40 = 2,
          WinNT50 = 3,
      }
      
      \[DllImport("Advapi32.dll")\]
      private static extern bool LogonUser(
          string lpszUserName,
          string lpszDomain,
          string lpszPassword,
          LogonType dwLogonType,
          LogonProvider dwLogonProvider,
          out IntPtr phToken);
      
      public static IntPtr LogonUser(
          string username, string password, string domain)
      {
          return LogonUser(username, password, domain, 
              LogonType.Network, LogonProvider.Default);
      }
      
      public static IntPtr LogonUser(
          string username, string password, string domain, 
          LogonType logonType, LogonProvider provider)
      {
          IntPtr ret = IntPtr.Zero;
          if (LogonUser(
              username, domain, password, 
              logonType, provider, out ret))
          {
              return ret;
          }
          else
              return IntPtr.Zero;
      }
      
      static void Main()
      {
          try
          {
              Console.Write("Username: ");
              string user = Console.ReadLine();
              Console.Write("Password: ");
              string password = Console.ReadLine();
      
              string domain = Environment.GetEnvironmentVariable("USERDOMAIN");
              Console.WriteLine("Domain: {0}", domain);
      
              IntPtr token = LogonUser(user, password, domain);
              if (IntPtr.Zero == token)
                  Console.WriteLine("Logon failed!");
              else
                  Console.WriteLine("Logon OK!");
      
          }
          catch(Exception ex)
          {
              Console.WriteLine(ex);
          }
      }
      

      }


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups