Determine if user is vaild without logon to windows again
Determine if user is vaild without logon to windows again
(OP)
Hi, Im trying to develop an application (database) for use on a common / shared PC where I need the application to be able to check (authenticate) a user based on their windows username and password without each user loggin on and off every time.
i.e. the PC is logged with either user A or a common resource user account. User B comes along opens the database enters the username and password and the application passes this to an API to check he is a valid user (return a simple yes / no for the username password combination) - if not the database closes.
Is this possible please?
I thiought about / tried using the "logonuser" call in advapi32.dll but didnt manage!
Thanks
i.e. the PC is logged with either user A or a common resource user account. User B comes along opens the database enters the username and password and the application passes this to an API to check he is a valid user (return a simple yes / no for the username password combination) - if not the database closes.
Is this possible please?
I thiought about / tried using the "logonuser" call in advapi32.dll but didnt manage!
Thanks
RE: Determine if user is vaild without logon to windows again
First delcare the external dll:
CODE
Then this function returns a boolean result for the check:
CODE
Dim token As Long
Dim result
Const LOGON32_LOGON_INTERACTIVE As Long = 2
Const LOGON32_LOGON_NETWORK As Long = 3
Const LOGON32_PROVIDER_DEFAULT As Long = 0
Const LOGON32_PROVIDER_WINNT50 As Long = 3
Const LOGON32_PROVIDER_WINNT40 As Long = 2
Const LOGON32_PROVIDER_WINNT35 As Long = 1
result = LogonUser(Username, Domain, Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token)
If result = 1 Then
ValidateLogin = True
Else
ValidateLogin = False
End If
End Function
Simply call the function as needed:
CODE
If ValidateLogin(Me.txt_name, Me.txt_password, "domain") = True Then
Me.txt_result = "Correct"
Else
Me.txt_result = "wrong!"
End If
End Sub
Hope this helps someone.