Dear NetRacer,
the code is FrameWork 2.0 compatible, it cannot be run in framework
1.1
Imports System
Imports System.Security
Imports System.Security.Principal
Imports System.Threading
Public Class WindowsIdentityCheck
' API's
Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As Boolean
Public Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal
handle As IntPtr) As Boolean
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Public Sub ValidateUserAccount(ByVal userName As String, ByVal
domainName As String, ByVal password As String)
Dim tokenHandle As New IntPtr(0)
Dim winPrin As WindowsPrincipal = Thread.CurrentPrincipal
Dim winId As WindowsIdentity = winPrin.Identity
Try
Const LOGON32_PROVIDER_DEFAULT As Integer = 0
'This parameter causes LogonUser to create a primary token.
Const LOGON32_LOGON_INTERACTIVE As Integer = 2
'Const SecurityImpersonation As Integer = 2
tokenHandle = IntPtr.Zero
' Call LogonUser to obtain a handle to an access token.
Dim returnValue As Boolean = LogonUser(userName,
domainName, password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, tokenHandle)
If False = returnValue Then
' The User Is Not A Valid User (Throw Exception Here)
Return
End If
' User Is Valid
CloseHandle(tokenHandle)
Catch e As Exception
End Try
End Sub
End Class
Regards,
Naveed Ahmad Bajwa
http://bajoo.blogspot.com/