Feedback
Did this article resolve your question/issue?

   

Article

How to authenticate a user's operating system username and password on Windows

« Go Back

Information

 
TitleHow to authenticate a user's operating system username and password on Windows
URL NameP21685
Article Number000136830
EnvironmentProduct: OpenEdge
Version: All supported versions
OS: Windows
Question/Problem Description
How to authenticate a user's operating system username and password on Windows

How to authenticate a user's operating system username and password credentials on Windows

How to authenticate Operating System Level user name and password credentials

How to call the Windows API LogonUser function using ABL?
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
One way to verify a user’s operating system username and password credentials is to call the WIN32 API Function LogonUser as demonstrated in the ABL code below.

The LogonUser function comes in 2 flavours:
- LogonUserA - Unicode.
- LogonUserW - Unicode.

The WIN32 API Function LogonUserA API is available on Windows NT and later.

On Windows NT and Windows 2000, the process/user that calls LogonUser must have the "Act as part of the Operating System" privilege/right.
On Windows XP and later, the above privilege is not required.
LogonUser is not implemented on Windows 95, Windows 98, or Windows Millennium Edition.


/*********************************************************************/
/* How to authenticate Operating System Level user name and password */
/*********************************************************************/
DEFINE VARIABLE clpszUserName AS CHARACTER FORMAT "X(15)" NO-UNDO.
DEFINE VARIABLE clpszDomain AS CHARACTER FORMAT "X(15)" NO-UNDO.
DEFINE VARIABLE clpszPassword AS CHARACTER FORMAT "X(15)" NO-UNDO.
DEFINE VARIABLE idwLogonType AS INTEGER NO-UNDO.
DEFINE VARIABLE idwLogonProvider AS INTEGER NO-UNDO.
DEFINE VARIABLE mphToken AS MEMPTR NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

UPDATE clpszUserName clpszDomain clpszPassword.

ASSIGN
SET-SIZE(mphToken) = 32
idwLogonType = 2
idwLogonProvider = 0.

PROCEDURE LogonUserA EXTERNAL "ADVAPI32.DLL":
DEFINE INPUT PARAMETER lpszUserName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER lpszDomain AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER lpszPassword AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER dwLogonType AS LONG NO-UNDO.
DEFINE INPUT PARAMETER dwLogonProvider AS LONG NO-UNDO.
DEFINE INPUT PARAMETER phToken AS MEMPTR NO-UNDO.
DEFINE RETURN PARAMETER intResult AS SHORT NO-UNDO.
END PROCEDURE.

RUN LogonUserA (INPUT clpszUserName,
INPUT clpszDomain,
INPUT clpszPassword,
INPUT idwLogonType,
INPUT idwLogonProvider,
INPUT mphToken,
OUTPUT intResult).

IF intResult > 0 THEN
MESSAGE "Logon authentication succeeded"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
MESSAGE "Logon authentication FAILED"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
Workaround
Notes
The USERDOMAIN environment variable can be used to obtain the Active Directory domain of the user logged into Windows. This value can be passed in the lpszDomain parameter to login to the same domain.
Last Modified Date9/13/2015 3:13 AM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.