Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use NT authentification for login
Message
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00337300
Message ID:
00342598
Views:
30
>I was wondering how to use the NT authentification for logging into a client server application (or regular standalone VFP app for that matter). I would want the user to login using the NT login and then just capture the userid portion and test that against my users table. Is this possible?

Yeah, you can use an API call to verify the user. But realize this won't actually log the user in under this account - you can't do that in a standalone application. Only services and the SYSTEM account can actually impersonate other accounts. Still the only way to really log on is to log off and back on.

The code below performs the username/password check against NT's security manager. You can read up in MSDN on how this function relates to security contexts etc. - but let me warn you: You won't want to mess with this stuff beyond the basics, because NT Security is sick and twisted if you need to get beyond the highlevel stuff and switching user context is among the most heinous code that you can write (I remember spending 3 days to write an File ACL setting utility and I had sample code <s>)...
FUNCTION LogonUser
************************************************************************
* wwAPI :: LogonUser
*********************************
***  Function: Check whether a username and password is valid
***    Assume: Account checking must have admin rights
***      Pass: Username, Password and optionally a server
***    Return: .T. or .F.
************************************************************************
LPARAMETERS lcUsername, lcPassword, lcServer

IF EMPTY(lcUsername)
   RETURN .F.
ENDIF
IF EMPTY(lcPassword)
   lcPassword = ""
ENDIF
IF EMPTY(lcServer)
   lcServer = "."
ENDIF         

#define LOGON32_LOGON_INTERACTIVE   2
#define LOGON32_LOGON_NETWORK       3
#define LOGON32_LOGON_BATCH         4
#define LOGON32_LOGON_SERVICE       5

#define LOGON32_PROVIDER_DEFAULT    0

DECLARE INTEGER LogonUser in WIN32API ;
       String lcUser,;
       String lcServer,;
       String lcPassword,;
       INTEGER dwLogonType,;
       Integer dwProvider,;
       Integer @dwToken
       
lnToken = 0
lnResult = LogonUser(lcUsername,lcServer,lcPassword,;
                     LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,@lnToken) 

DECLARE INTEGER CloseHandle IN WIN32API INTEGER
CloseHandle(lnToken)

RETURN IIF(lnResult=1,.T.,.F.)
ENDFUNC
* wwAPI :: LogonUser
>
>Kevin
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform