?
Solved

Authenticate windows login password using VBA

Posted on 2006-06-05
4
Medium Priority
?
3,379 Views
Last Modified: 2008-02-01
I am writing an application using VBA in Excel and would like to have the user enter their windows password in an inputbox and then have the application check the password is correct against their actual windows login password.  Is this possible?
0
Comment
Question by:pbsl-it
4 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16833426
(This doesn't answer your question, but...)  Just a thought.. if you're running VBA, wouldn't that imply that the user has successfully passed the Windows password login, if the Windows password is set?
0
 
LVL 6

Expert Comment

by:junglerover77
ID: 16839037
Yes, it's possible, but you must use some NETAPIs. So you will need to build an Activex DLL for it before you can use those APIs in VBA.

Here is a sample:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20430176.html

Regards,
Jungle
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 1500 total points
ID: 16841713
Something like this would work


Option Explicit

Private Declare Function NetUserChangePassword Lib "Netapi32" ( _
    ByVal domainname As Long, _
    ByVal UserName As Long, _
    ByVal OldPassword As Long, _
    ByVal NewPassword As Long) As Long

Private Const NERR_SUCCESS = 0
Private Const INVALID_PASSWORD = 86&
Private Const ACCESS_DENIED = 5

Public Function WindowPassword( _
    ByVal oldpw As String, _
    ByVal newpw As String, _
    Optional ByVal UserName As String = vbNullString) As Boolean
   
    Dim NetRet As Long
       
    'If UserName not specified, _
        defaults to current user logged on.
   
   NetRet = NetUserChangePassword(0&, _
        StrPtr(UserName), _
        StrPtr(oldpw), _
        StrPtr(newpw))
       
    Select Case NetRet
        Case NERR_SUCCESS
            WindowPassword = True
        Case INVALID_PASSWORD
            MsgBox "Invalid Password"
        Case ACCESS_DENIED
            MsgBox "Access denied"
    End Select
   
End Function

Private Sub Command1_Click()

    Dim arg As String
    arg = InputBox("Enter Password", "Window logon", vbNullString)
   
    Select Case arg
        Case vbNullString
       
        If WindowPassword(arg, arg) Then
            MsgBox "The current users password is blank."
        End If
       
        Case Else
        If WindowPassword(arg, arg) Then
            MsgBox "Windows Logon Password: " & arg
        End If
    End Select
   
   
End Sub
0
 

Author Comment

by:pbsl-it
ID: 16850856
Thanks for the help.  Using "NetUserChangePassword" will be sufficient for what I need.

Cheers

Barry
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses

750 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