Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating userid x password
Message
From
28/02/2004 06:17:05
 
 
To
27/02/2004 15:15:08
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00881067
Message ID:
00881767
Views:
27
Hi Alex,

>Nice routine. I just tested it in XP Pro in our corporate network and it worked fine.

Searching and testing a bit more, got to this more complete example:
 Declare Integer CloseHandle In Kernel32 Integer hObject

 Declare Integer GetLastError  In Kernel32

 Declare Integer FormatMessage In Kernel32 Integer dwFlags        , ;
                                           String  lpSource       , ;
                                           Integer dwMessageId    , ;
                                           Integer dwLanguageId   , ;
                                           String  @lpBuffer      , ;
                                           Integer nSize          , ;
                                           Integer Arguments
              
 #Define FORMAT_MESSAGE_FROM_SYSTEM 4096

 Declare Integer LogonUser In advapi32 String  lpszUsername,; 
                                       String  lpszDomain,; 
                                       String  lpszPassword,; 
                                       Integer dwLogonType,; 
                                       Integer dwLogonProvider,; 
                                       Integer @phToken 
* dwLogonProvider:

 #Define LOGON32_PROVIDER_DEFAULT  0
 #Define LOGON32_PROVIDER_WINNT50  3
 #Define LOGON32_PROVIDER_WINNT40  2
 #Define LOGON32_PROVIDER_WINNT35  1

* dwLogonType:

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

 cUserId   = "myuserid"
 cPassword = "mypassword"
 cDomain   = "mydomain"

 nToken  = 0

 nHandle = LogonUser (cUserId                  , ;
                      cDomain                  , ;
                      cPassword                , ;
                      LOGON32_LOGON_INTERACTIVE, ;
                      LOGON32_PROVIDER_DEFAULT , ;
                      @nToken)

 If nHandle > 0
    MessageBox  ("Password is correct!")
    CloseHandle (nToken)
 else
    nLastError   = GetLastError  ()
    cMessageText = Space         (256)
    nRetCode     = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, ;
                                  0                         , ;
                                  nLastError                , ;
                                  0                         , ;
                                  @cMessageText             , ;
                                  256                       , ;
                                  0)

    MessageBox (cMessageText)
 endif
Where it was added the declarations of CloseHandle, GetLastError and FormatMessage, the passing of nToken by reference (@nToken) and the closing of the token that represents the specified user, issuing a CloseHandle (nToken). Also when LogonUser fails GetLastError and FormatMessage are called to show wich error has occurred.

I'm still testing and searching... :)

Fernando
Previous
Reply
Map
View

Click here to load this message in the networking platform