Excel 64 bit - Validating a users windows login credentials

TheBigDog

Board Regular
Joined
Aug 5, 2002
Messages
59
Hi, I have been using the code below in Excel 32 bit environment on a domain network (at work) with success for 10+ yrs.

Validating a users windows login credentials using SSPI

However, recent change of Excel version to 64bit rendered the code non-functional. We haven't had a lot of success in converting the code above from 32bit to 64bit.

Is there a different or better way to do windows login authentication (via domain) that is friendly with Excel 64bit?

Thanks in advance!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I've always had success with fosUserName, which from limited research, should work in 64 bit. If not, you just need to put conditional compilation code at the beginning. See answers re 64 bit here API: Get Login name

Unless you have a specific need for what 64 bit brings to Office, there's no reason to make everyone's life more difficult, but it seems to be how IT guys roll. If it's the latest, it must be the best. For a while M$ was even suggesting that everyone use 32 bit because of the problems they introduced.
 
Upvote 0
I've always had success with fosUserName, which from limited research, should work in 64 bit. If not, you just need to put conditional compilation code at the beginning. See answers re 64 bit here API: Get Login name

Unless you have a specific need for what 64 bit brings to Office, there's no reason to make everyone's life more difficult, but it seems to be how IT guys roll. If it's the latest, it must be the best. For a while M$ was even suggesting that everyone use 32 bit because of the problems they introduced.

The way that I used the original code (as hyperlinked in my original post) is

  1. Excel form (VBA) prompt user for domain user ID and PW
  2. Use the code to validate the user ID / PW against domain.
  3. Upon successful validation, code continues to perform other assigned items.
  4. If validation failed, no further action is performed.
Do you have code for authentication that's 64bit compatible? I am afraid getting the login name is not going to help my course above.

P.S. Yes, it is IT mandate. I don't have a choice..unfortunately. :(
 
Upvote 0
I thought you were using the other code in the same fashion. That function gets the Windows Login User name, which you then lookup in a table in code. If it's there, they are in. If not, they don't get in, thus you can dispense with the password stuff altogether - unless users are sharing a Windows login session. Here's what I have for various ptrSafe declarations:

VBA Code:
#If VBA7 Then
  Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As Long
  Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As Long
  Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As LongPtr, ByVal dwBytes As LongPtr) As Long
  Declare PtrSafe Function CloseClipboard Lib "USER32" () As Long
  Declare PtrSafe Function OpenClipboard Lib "USER32" (ByVal hwnd As LongPtr) As Long
  Declare PtrSafe Function EmptyClipboard Lib "USER32" () As Long
  Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
  Declare PtrSafe Function SetClipboardData Lib "USER32" (ByVal wFormat As LongPtr, ByVal hMem As LongPtr) As Long
#Else
  Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  Declare Function CloseClipboard Lib "USER32" () As Long
  Declare Function OpenClipboard Lib "USER32" (ByVal hwnd As Long) As Long
  Declare Function EmptyClipboard Lib "USER32" () As Long
  Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
  Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
#End If
 
Upvote 0
I thought you were using the other code in the same fashion. That function gets the Windows Login User name, which you then lookup in a table in code. If it's there, they are in. If not, they don't get in, thus you can dispense with the password stuff altogether - unless users are sharing a Windows login session. Here's what I have for various ptrSafe declarations:

VBA Code:
#If VBA7 Then
  Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As Long
  Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As Long
  Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As LongPtr, ByVal dwBytes As LongPtr) As Long
  Declare PtrSafe Function CloseClipboard Lib "USER32" () As Long
  Declare PtrSafe Function OpenClipboard Lib "USER32" (ByVal hwnd As LongPtr) As Long
  Declare PtrSafe Function EmptyClipboard Lib "USER32" () As Long
  Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
  Declare PtrSafe Function SetClipboardData Lib "USER32" (ByVal wFormat As LongPtr, ByVal hMem As LongPtr) As Long
#Else
  Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  Declare Function CloseClipboard Lib "USER32" () As Long
  Declare Function OpenClipboard Lib "USER32" (ByVal hwnd As Long) As Long
  Declare Function EmptyClipboard Lib "USER32" () As Long
  Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
  Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
#End If


See the description of the code below (copy from the hyperlinked code in my original post.). You must enter Username and password to authenticate against the domain.


'Purpose : Checks the username and password are a valid login.
'Inputs : sUserName The username for the account to check
' sPassword The password for the account to check
' [sDomain] If omitted uses the local account database, else uses specified domain
'Outputs : Returns True if the password and user name are valid.
'Author : Andrew Baker
'Date : 25/03/2000
'Notes :

Public Function ValidateUser(sUserName As String, sPassword As String, Optional sDomain As String = vbNullString) As Boolean
 
Upvote 0
Sorry, I know nothing of providing credentials to a domain. Best I can do is show 32 bit vs 64 bit code for API calls as per your original question. Perhaps follow the email link at that site if you haven't already and ask for help to convert. Maybe a line like this

Private Declare Function NT4FreeContextBuffer Lib "security" Alias "FreeContextBuffer" (ByVal pvContextBuffer As Long) As Long
needs to be more like

Private Declare PtrSafe Function NT4FreeContextBuffer Lib "security" Alias "FreeContextBuffer" (ByVal hMem As LongPtr) As Long
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top