Solved

Validating a password

Posted on 1997-06-10
3
164 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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