Solved

I need to sync a VB 6 program's User ID and Password with the Windows User ID and Password

Posted on 2013-06-03
5
248 Views
Last Modified: 2013-06-06
I need to sync a VB 6 program's User ID and Password with the Windows User ID and Password.

How can I capture the Windows User's Password in Visual Basic 6?  

The VB 6 program uses the Windows User ID and Password to commit a scientific action that a user performs.  Just in case someone walks away from the PC and another user goes to walks up and commits the scientific action.

Thanks!
0
Comment
Question by:AndrewBanfer
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Peter Kiprop
ID: 39216457
Hi AndrewBanfer,

There is no way you can capture windows users password. You can always get if the right password has been entered or not.

The below code is a sample of what i have used to authenticate users using windows paswords. You can always use thesame to update users password to a table if it returns a success etc.
]

Option Explicit

Public LoginSucceeded As Boolean
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
Const LOGON32_PROVIDER_DEFAULT = 0&
Const LOGON32_LOGON_NETWORK = 3&

Private Sub cmdCancel_Click()
    LoginSucceeded = False
    Me.Hide
End Sub

' Check whether a username/password pair is correct
'
' if DOMAIN is omitted, it uses the local account database
' and then asks trusted domains to search their account databases
' until it finds the account or the search is exhausted
' use DOMAIN="." to search only the local account database
'
'  IMPORTANT: works only under Windows NT,2000 and 2003

Private Function CheckWindowsUser(ByVal UserName As String, _
    ByVal Password As String, Optional ByVal Domain As String) As Boolean
    Dim hToken As Long, ret As Long

    ' provide a default for the Domain name
    If Len(Domain) = 0 Then Domain = vbNullString
    ' check the username/password pair
    ' using LOGON32_LOGON_NETWORK delivers the best performance
    ret = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, _
        LOGON32_PROVIDER_DEFAULT, hToken)
    
    ' a non-zero value means success
    If ret Then
        CheckWindowsUser = True
        CloseHandle hToken
        'Load main formor do action etc
      '  Unload Me 
    Else
        MsgBox "Credentials supplied are invalid. Please try again.", vbExclamation
    End If

End Function
Private Sub cmdOK_Click()
    CheckWindowsUser txtUserName, txtPassword, TxtDomain
End Sub

Open in new window

0
 

Author Comment

by:AndrewBanfer
ID: 39216576
Thanks,  I'll give this a try shortly.
0
 

Author Comment

by:AndrewBanfer
ID: 39222798
Hi Pthepebble,

I got midway through implementing your solution and talked to my client again.  

Is there a way to confirm a Windows User is valid to use the PC without being the Windows User who is actually on the PC?

For example,
1) we are acquiring data from an analytical instrument connected to a Windows PC.  

2)  We can't use the Windows Inactivity Logout because the instrument will stop acquiring data.  

3)  There are 3 shifts of personnel running the analytical instrument.  The instrument can acquire data for 20 hours every day.  So, one shift will leave while logged into Windows to keep the analytical instrument acquiring data.  If we make a program to require a login after a period of inactivity.  Can we check that the new user is a valid user of the PC without checking that the user is valid to the initial person logged in?
0
 
LVL 6

Accepted Solution

by:
Peter Kiprop earned 500 total points
ID: 39224638
Hi AndrewBanfer,

This is not possible, unless done administratively. probably the use of biometric will help
0
 

Author Closing Comment

by:AndrewBanfer
ID: 39225507
Thanks very much and have a great day!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

759 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

23 Experts available now in Live!

Get 1:1 Help Now