473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

LDAP VBA Authentication

I couldn't find an answer to how to use Active Directory for authentication using just VBA. I did find an example of logging in with alternate credentials which was the answer. The premise is that you attempt to login with the username and password combination. If it fails you get an error returned, if not the combination is valid. Since the userpassword field is write only, this is the only way to validate a password.

Expand|Select|Wrap|Line Numbers
  1. Const ADS_SECURE_AUTHENTICATION = &H1
  2. Const ADS_SERVER_BIND = &H200
  3. Public Sub CheckUser()
  4. If Authenticate(Authentication_Form.UserName.Text, Authentication_Form.Password.Value) Then
  5. MsgBox "Login Successful"
  6. Else
  7. MsgBox "User name and password combination did not match"
  8. End If
  9. End Sub
  10.  
  11. 'Verify username and password combination are valid
  12. Public Function Authenticate(strUser As String, strPassword As String) As Boolean
  13. On Error GoTo ReportError
  14. ' Specify a server (Domain Controller).
  15. strServer = "" 'Enter your server name here
  16.  
  17. ' Determine DNS domain name. Use server binding and alternate ‘ credentials. The value of strDNSDomain can also be hard coded.
  18. Set objNS = GetObject("LDAP:")
  19. Set objRootDSE = objNS.OpenDSObject("LDAP://" & strServer & "/RootDSE", strUser, strPassword, ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION)
  20.  
  21. strDNSDomain = objRootDSE.Get("defaultNamingContext")
  22.  
  23. Set objCommand = CreateObject("ADODB.Command")
  24. Set objConnection = CreateObject("ADODB.Connection")
  25. objConnection.Provider = "ADsDSOObject"
  26. objConnection.Properties("User ID") = strUser
  27. objConnection.Properties("Password") = strPassword
  28. objConnection.Properties("Encrypt Password") = True
  29. objConnection.Properties("ADSI Flag") = ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION
  30. objConnection.Open "Active Directory Provider"
  31. Set objCommand.ActiveConnection = objConnection
  32. Authenticate = True 'If you were able to login the function returns true, it returns false if you received an error
  33.  
  34. ReportError:
  35.    'This is the error number displayed when the login is not successful
  36.    If Err.Number = -2147023570 Then
  37.       Authenticate = False
  38.    End If
  39. End Function
Feb 24 '12 #1
0 3882

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: dmcconkey | last post by:
Hi folks, I've been searching for a while and haven't found my specific question anywhere else. If this has already been asked, please accept my appologies and point me to the appropriate...
0
by: DavidR | last post by:
I have some Java code that I need to mimic to have my ASP/C# web application (C# being the middle-tier) authenticate to a mainframe (running AIX) using LDAP. The Java code looks something like...
1
by: rajens00 | last post by:
LDAP authentication fails with the final release version of ASP.Net 2.0 (and Beta 2 also). I suspect it's a legit bug. Any ideas how to report it?? The following code works fine with Framework...
2
by: duncan beaumont | last post by:
Hi, - SQLserver 2000 - Yellowfin 2.4 - Windows 2003 server I have been asked to investigate seting up LDAP authentication to access our Yellowfin reporting.
4
by: Josephine | last post by:
Hi, Can anyone help me on create LDAP authentication code in asp file? If successful then will redirect user to appropriate page. From: Jo
0
by: jayadevi | last post by:
Is it possible to configure an IIS to do both LDAP authentication and Windows authentication? For ex: Suppose one application of server A is hosted in IIS. The requests come from two different...
5
by: ananth | last post by:
Hi All, I am new to ASP.I don't even know how to start i have a project where in i have to create a ASP code that does a LDAP authentication for a Domino sever.The requirement is user will...
1
by: jesbuddy07 | last post by:
Hello, I'm using IIS 5 and PHP 4.3.5. I have an html page, page1, that resides at member.company.com server. It contains a form asking a user to login. I then check the login by connecting to...
1
by: Gladiator | last post by:
Hi , I have a solaris box on which the LDAP authentication is configured. I have installed DB2 on it . I have granted connect privilage to a LDAP user. When i try to connect to the database...
1
by: santhanalakshmi | last post by:
Hi, I am having a login screen. I too installed Perl-ldap in windows xp. I don't know, how to start my coding for the LDAP AUTHENTICATION. Thanks is advance....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.