LogonUser API 
Author Message
 LogonUser API

Hi

I am trying to use LogonUser to verify a user. But it will not work, the API
always return 0. Anyone have had the same problem and solved it?

The code is here:

**************************************
Private Declare Function LogonUser _
   Lib "Advapi32" Alias "LogonUserA" _
   (ByVal lpszUsername As String, _
    ByVal lpszDomain As Any, _
    ByVal lpszPassword As String, _
    ByVal dwLogonType As Long, _
    ByVal dwLogonProvider As Long, _
    phToken As Long) As Long

Const LOGON32_PROVIDER_DEFAULT    As Long = 0&
Const LOGON32_PROVIDER_WINNT35    As Long = 1&
Const LOGON32_LOGON_INTERACTIVE   As Long = 2&
Const LOGON32_LOGON_NETWORK       As Long = 3&
Const LOGON32_LOGON_BATCH         As Long = 4&
Const LOGON32_LOGON_SERVICE       As Long = 5&

Public Function CheckUserName(UserName As String, Password As String) As
Boolean
Dim lReturn As Long
Dim bOk As Boolean
Dim lToken As Long

   lReturn = LogonUser(UserName, 0&, Password, LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT, lToken)

   If lReturn = 0 Then
      bOk = False
   Else
      bOk = True
   End If

   CheckUserName = bOk

End Function

****************************************

/Per-Olof



Sun, 10 Oct 2004 17:31:57 GMT  
 LogonUser API
I tested the codes; Change "ByVal lpszDomain As Any" to "ByVal lpszDomain
As String", and in the code specify the domain name. It works, the return
value is nonzero.

Private Declare Function LogonUser _
   Lib "Advapi32" Alias "LogonUserA" _
   (ByVal lpszUsername As String, _
    ByVal lpszDomain As String, _
    ByVal lpszPassword As String, _
    ByVal dwLogonType As Long, _
    ByVal dwLogonProvider As Long, _
    phToken As Long) As Long

lReturn = LogonUser(UserName, "Domainname", Password,
LOGON32_LOGON_NETWORK, _
LOGON32_PROVIDER_DEFAULT, lToken)

If we want to verify a local user, set the domain name's value to "".

Best Regards,

Alick Ye

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. Copy right, 2002 Microsoft Corporation.
All rights reserved.

--------------------

Subject: LogonUser API
Date: Wed, 24 Apr 2002 11:31:57 +0200
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

Newsgroups: microsoft.public.vb.com
NNTP-Posting-Host: h36n1fls35o985.telia.com 217.210.52.36
Path: cpmsftngxa07!tkmsftngp01!tkmsftngp03
Xref: cpmsftngxa07 microsoft.public.vb.com:27419
X-Tomcat-NG: microsoft.public.vb.com

Hi

I am trying to use LogonUser to verify a user. But it will not work, the API
always return 0. Anyone have had the same problem and solved it?

The code is here:

**************************************
Private Declare Function LogonUser _
   Lib "Advapi32" Alias "LogonUserA" _
   (ByVal lpszUsername As String, _
    ByVal lpszDomain As Any, _
    ByVal lpszPassword As String, _
    ByVal dwLogonType As Long, _
    ByVal dwLogonProvider As Long, _
    phToken As Long) As Long

Const LOGON32_PROVIDER_DEFAULT    As Long = 0&
Const LOGON32_PROVIDER_WINNT35    As Long = 1&
Const LOGON32_LOGON_INTERACTIVE   As Long = 2&
Const LOGON32_LOGON_NETWORK       As Long = 3&
Const LOGON32_LOGON_BATCH         As Long = 4&
Const LOGON32_LOGON_SERVICE       As Long = 5&

Public Function CheckUserName(UserName As String, Password As String) As
Boolean
Dim lReturn As Long
Dim bOk As Boolean
Dim lToken As Long

   lReturn = LogonUser(UserName, 0&, Password, LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT, lToken)

   If lReturn = 0 Then
      bOk = False
   Else
      bOk = True
   End If

   CheckUserName = bOk

End Function

****************************************

/Per-Olof



Mon, 11 Oct 2004 16:35:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. LogonUser API Impersonation to SQL Server

2. Createprocesswithlogon and LogonUser APIs

3. LogonUser API function - question

4. Trouble with LogonUser API

5. LogonUser API problem

6. Repost: Help with LogonUser API call needed

7. LogonUser API help

8. LogonUser API call help needed

9. Pls Help! LogonUser API Problem

10. Using LogonUSer API fails

11. How do I use Logonuser API in VB?

12. How to use LogonUser API Call?

 

 
Powered by phpBB® Forum Software