Solved

Validating a password

Posted on 1997-06-10
3
156 Views
Last Modified: 2008-03-06
Hello!

I would like to validate a password using VB 5.0 against either the
password you enter into Windows 95 or against the network. I can find out how to get the current user id - but not to validate the password!!!!

Thanks

David
0
Comment
Question by:denaumow
3 Comments
 
LVL 1

Expert Comment

by:ksleung
ID: 1427039
Due to the security, you will not know the password (encrypted or not) and you do not know the encryption methodology. Hence, you have to try to pass your password and id to the OS an let it do the validation. You have to have your handling routine for the incorrect password (the OS rejects your login).
0
 

Author Comment

by:denaumow
ID: 1427040
I know that you have to have the OS validate the password - butI cannot find a windows API Call to have the OS do the validation.  What/How do I get VB5 to ask the OS to validate a password? (thatis heart of the original question.)
0
 
LVL 5

Accepted Solution

by:
y96andha earned 200 total points
ID: 1427041
This is how to do a user validation. In order for this to work, the user account which runs the program must either be the SYSTEM account or an account with the SeTcbPrivilege - "Act as part of the operating system" user right.

The user account which is validated must have the appropriate privilege too, depending on whether you will use
LOGON32_LOGON_BATCH, LOGON32_LOGON_INTERACTIVE or LOGON32_LOGON_SERVICE.

Declarations:


Private 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
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Const LOGON32_PROVIDER_DEFAULT = 0
Private Const LOGON32_LOGON_BATCH = 4
Private Const LOGON32_LOGON_INTERACTIVE = 2
Private Const LOGON32_LOGON_SERVICE = 5



Validation function:

Replace username, domain and password with the values to be verified. Use either LOGON32_LOGON_BATCH, LOGON32_LOGON_INTERACTIVE or LOGON32_LOGON_SERVICE. In this example I use LOGON32_LOGON_BATCH, which means that the user account which is being verified must have the "Logon as a batch job" user right.


Private Sub Command1_Click()
    Dim token As Long, status As Long
    token = 0
    status = LogonUser("username", "domain", "password", _
LOGON32_LOGON_BATCH, _
LOGON32_PROVIDER_DEFAULT, token)
    If status = 0 Then
    MsgBox "Logon Failed"
    Else
    MsgBox "Logon successful"
    CloseHandle token
    End If
End Sub

I have never tried this in Windows 95, though, only in NT.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now