May 1, 2010 08:59 PM
(This post was last modified: May 2, 2010 02:13 PM by codepoet.)
originally posted on dotnet-snippets.com
Description:
This function checks a windows user password whether it is valid and matching to the given username.
If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
Description:
This function checks a windows user password whether it is valid and matching to the given username.
Code
Private Declare Auto Function LogonUser Lib "advapi32.dll" ( _
ByVal lpszUsername As String, _
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As LogonType, _
ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) _
As Integer
Private Declare Auto Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As IntPtr) _
As Boolean
Public Enum LogonType As Integer
LOGON32_LOGON_INTERACTIVE = 2
LOGON32_LOGON_NETWORK = 3
LOGON32_LOGON_BATCH = 4
LOGON32_LOGON_SERVICE = 5
LOGON32_LOGON_UNLOCK = 7
LOGON32_LOGON_NETWORK_CLEARTEXT = 8
LOGON32_LOGON_NEW_CREDENTIALS = 9
End Enum
Public Function IsNTPasswordValid(ByVal Username As String, ByVal Password As String, Optional ByVal Domain As String = "") As Boolean
Dim Token As New IntPtr
LogonUser(Username, Domain, Password, LogonType.LOGON32_LOGON_INTERACTIVE, 0, Token)
CloseHandle(Token)
If Token.ToInt32 <> 0 Then Return True
End FunctionIf You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
PHP & .NET Contributor.


