Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old April 22nd, 2005, 11:01 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It seems safe to presume that if they have gotten into Windows far enough to run your app, they have a valid login. . .
Reply With Quote
  #12 (permalink)  
Old May 4th, 2005, 05:02 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 Doug, I don't know if you're still interested in this but, for the sake of the archive, I stumbled across this interesting piece of code which uses the LogonUser WinAPI function to validate a given user name and password (note, though, that it does not get the current password of the user)
Code:
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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
    Long
Const LOGON32_PROVIDER_DEFAULT = 0&
Const LOGON32_LOGON_NETWORK = 3&

' Check whether a username/password pair is correct
'
' if DOMAIN is omitted, it uses the local account database
' and then asks trusted domains to search their account databases
' until it finds the account or the search is exhausted
' use DOMAIN="." to search only the local account database

Private Function CheckWindowsUser(ByVal UserName As String, _
    ByVal Password As String, Optional ByVal Domain As String) As Boolean

    Dim hToken As Long, ret As Long

    ' provide a default for the Domain name
    If Len(Domain) = 0 Then Domain = vbNullString
    ' check the username/password pair
    ' using LOGON32_LOGON_NETWORK delivers the best performance
    ret = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, _
        LOGON32_PROVIDER_DEFAULT, hToken)

    ' a non-zero value means success
    If ret Then
        CheckWindowsUser = True
        CloseHandle hToken
    End If

End Function
BTW I found it on http://www.vb2themax.com

rgds
Phil
Reply With Quote
  #13 (permalink)  
Old May 4th, 2005, 05:10 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 Doug, I don't know if you're still interested in this but, for the sake of the archive, I stumbled across this interesting piece of code which uses the LogonUser WinAPI function to validate a given user name and password (note, though, that it does not get the current password of the user)
Code:
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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
    Long
Const LOGON32_PROVIDER_DEFAULT = 0&
Const LOGON32_LOGON_NETWORK = 3&

' Check whether a username/password pair is correct
'
' if DOMAIN is omitted, it uses the local account database
' and then asks trusted domains to search their account databases
' until it finds the account or the search is exhausted
' use DOMAIN="." to search only the local account database

Private Function CheckWindowsUser(ByVal UserName As String, _
    ByVal Password As String, Optional ByVal Domain As String) As Boolean

    Dim hToken As Long, ret As Long

    ' provide a default for the Domain name
    If Len(Domain) = 0 Then Domain = vbNullString
    ' check the username/password pair
    ' using LOGON32_LOGON_NETWORK delivers the best performance
    ret = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, _
        LOGON32_PROVIDER_DEFAULT, hToken)

    ' a non-zero value means success
    If ret Then
        CheckWindowsUser = True
        CloseHandle hToken
    End If

End Function
BTW I found it on http://www.vb2themax.com

rgds
Phil
Hi Phil,
I tried the same code in my VB 6.0 std exe application to validate login agnst domain users.But unfortunately, "LogonUser" returns 0 (zero) even after providing correct username,password & domain name.Mine is a Win2000 domain server in the same n/w and my Vb appln will be installed in Win98/2000 Prof/XP.
Is there any way i can get the sample, working code for user validation be using
ActiveDirectory?
Plz give me a suggestion..
rgds & thanx in advance,
svmenon

Reply With Quote
  #14 (permalink)  
Old May 4th, 2005, 06:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi svmenon,

If you read the thread you'll see that this is just a bit of code I found on another site, I've never used it myself.

If you look at Microsoft's documentation for the LogonUser API function you'll see that it requires the SE_TCB_NAME privilege on Win2000, so maybe your process doesn't have the necessary rights?

What do you get from err.LastDllError just after the LogonUser call?
Could
Reply With Quote
  #15 (permalink)  
Old May 4th, 2005, 07:02 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default


err.LastDllError value returned is 1314

rgds,
svm

Reply With Quote
  #16 (permalink)  
Old May 4th, 2005, 08:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by sujithvmenon

err.LastDllError value returned is 1314

rgds,
svm
error 1314 is ERROR_PRIVILEGE_NOT_HELD, which (according to the Microsoft docs on LogonUser - did you read this?) is the exact error you will get if the process trying to call LogonUser does not have the SE_TCB_NAME privilege. So the problem is not with the code but with the user/process account that is trying to run the code.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i mail the password to the user? ayem Visual Studio 2008 3 August 13th, 2008 06:52 AM
password/user functions sola Access 3 January 13th, 2006 08:49 AM
what is the password and user id for ........! Random Servlets 1 November 8th, 2005 02:59 AM
validating user input hosefo81 Javascript How-To 12 March 3rd, 2004 09:32 AM
Validating user input stu9820 VB.NET 2002/2003 Basics 2 January 15th, 2004 12:51 PM



All times are GMT -4. The time now is 10:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.