Question Window form application should login with window credential

sels1987

New member
Joined
Jun 19, 2011
Messages
3
Programming Experience
1-3
Hi,
I want to develop a window form application,which have a login form as first window. User has to give their system login username and password only(this is requirement) to avoid new registration. I have to verify the supplied username and password with the system login username and password. Is there a way to implement this requirement.

Kindly give your reply to the above requirement


Regards,
Selvam S
 
Last edited:

kpmsiva

New member
Joined
Mar 13, 2009
Messages
1
Programming Experience
Beginner
Hi sels,

You can make use of LogonUser function. The LogonUser function validates the user name and password and returns True if the user name and the password are valid.

Here goes to the sample code:

VB.NET:
rivate Declare Function LogonUser Lib "Advapi32" Alias "LogonUserA" (ByVal _
    lpszUserName As String, ByVal lpszDomain As String, _
    ByVal lpszPassword As String, ByVal dwLogonType As Long, _
    ByVal dwLogonProvider As Long, phToken As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
    Long
Const LOGON32_PROVIDER_DEFAULT = 0&
Const LOGON32_LOGON_NETWORK = 3&

' Check whether a username/password pair is correct
'
' if DOMAIN is omitted, it uses the local account database
' and then asks trusted domains to search their account databases
' until it finds the account or the search is exhausted
' use DOMAIN="." to search only the local account database
'
'  IMPORTANT: works only under Windows NT and 2000

Private Function CheckWindowsUser(ByVal UserName As String, _
    ByVal Password As String, Optional ByVal Domain As String) As Boolean
    Dim hToken As Long, ret As Long

    ' provide a default for the Domain name
    If Len(Domain) = 0 Then Domain = vbNullString
    ' check the username/password pair
    ' using LOGON32_LOGON_NETWORK delivers the best performance
    ret = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, _
        LOGON32_PROVIDER_DEFAULT, hToken)
    
    ' a non-zero value means success
    If ret Then
        CheckWindowsUser = True
        CloseHandle hToken
    End If

End Function
 
Last edited:
Top Bottom