×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Determine if user is vaild without logon to windows again

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

RE: Determine if user is vaild without logon to windows again

(OP)
Hi - OK I found a solution:

First delcare the external dll:

CODE

Public Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As Long) As Long

Then this function returns a boolean result for the check:

CODE

Private Function ValidateLogin(ByVal Username As String, ByVal Password As String, ByVal Domain As String) As Boolean

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

Private Sub cmb_auth_Click()

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close