From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

launch native windows login credential dialog with winAPI

Solved!
Go to solution

I'm working on a login/privilege escalation feature that uses domain user/PW and got LDAP authentication figured out, but I was hoping to avoid just using a labview string control for the password entry b/c of security (VI Server, unencrypted, etc). I am trying to call CredUIPromptForWindowsCredentials  and launch the native windows login dialog.  It is a function in the System32\credui.dll but I can't get the parameters right.  I keep getting a return value of A0(160) and no dialog.  I think it is the PCREDUI_INFO type screwing it up. It needs:

 

DWORD WINAPI CredUIPromptForWindowsCredentials(
_In_opt_    PCREDUI_INFO pUiInfo,
_In_        DWORD        dwAuthError,
_Inout_     ULONG        *pulAuthPackage,
_In_opt_    LPCVOID      pvInAuthBuffer,
_In_        ULONG        ulInAuthBufferSize,
_Out_       LPVOID       *ppvOutAuthBuffer,
_Out_       ULONG        *pulOutAuthBufferSize,
_Inout_opt_ BOOL         *pfSave,
_In_        DWORD        dwFlags
);

 

I've been told that Rolf would be able to solve this in 30 seconds.  Help me LabVIEW! You're my only hope!

0 Kudos
Message 1 of 13
(6,266 Views)
Solution
Accepted by topic author drummaniac83

Josh,

 

It's easier to call it in a wrapper C dll.

I manage to get this window to show up:

 

Untitled.png

 

George

George Zou
Message 2 of 13
(6,230 Views)

zou, do you have the Login.dll DLL and its source (if you can make it available) - can't run your example without it and it would be good to know what's inside it (it is asking people to enter their username/password after all...) but I'm curious to try it.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 3 of 13
(6,171 Views)

The dll was striped by the forum.

It's calling CredUIPromptForWindowsCredentials

 

 

George Zou
0 Kudos
Message 4 of 13
(6,149 Views)

George,

 

I figured the C wrapper might be the way to go.  It's quite trival to create the structures and data types required in C/CVI, but very complicated in LabVIEW.  On the lava forum, Rolf K said the issue is probably the pointers inside the struct.  I think his instincts are right.

0 Kudos
Message 5 of 13
(6,137 Views)

The dll and source code can be download from my dropbox:

https://www.dropbox.com/s/74ccqtt40btxg7j/Login.zip?dl=0

 

 It's just a demo for the ideal.

Not finished.

 

George Zou
Message 6 of 13
(6,132 Views)

Sam,

Inside the C dll you basically have to call 2 windows dll functions which are part of the credui.dll:

 

CredUnPackAuthenticationBuffer

and

CredUIPromptForWindowsCredentials

 

The first function unpacks the buffer you receive after calling the first function which pops open the native windows login screen and returns a pointer to the buffer.  Once the buffer is unpacked and you have a string representation of the username and PW you can feed it into a .net function PrincipalConext.ValidateCredentials and get a verification of the username and password.  This method works for both local logins and network logins of certain types (Active directory)

 

Relavent Links:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa375178(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/bb154889(v=vs.110).aspx

 

Message 7 of 13
(6,124 Views)
Any chance of building a release version of the DLL? As it's built in debug mode (and I don't have VS2012), it requires the debug libraries (msvcr110d.dll as opposed to msvcr110.dll) to load.

LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 13
(6,103 Views)

Sam,

 

The link has been updated to include the release version dll.

 

As I said this dll is not finished, just a demo.  It doesn't return the user input.

Reasons: 1. I 'm sure Josh can finish it; 2. I think the user input should be verified within the dll, and return only a boolean.

 

 P.S. by the way, VS express version is free.  You can download it from MS.

 

 

George Zou
0 Kudos
Message 9 of 13
(6,097 Views)

Hi zou,

 

It looks like the dropbox link is no longer available. Can you re-upload the code?

 

Thanks,

Jenna

0 Kudos
Message 10 of 13
(5,554 Views)