473,396 Members | 2,018 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.

ADSI Authentication Problem in ASP

Hi,

I've one system in which Active directory is installed.
That system is the domain controller as well as web
server - A test machine.
Trying all following to Authenticate Users using VB as
well as ASP.
I need ASP solution (and no component required etcc..).
Things seems to work fine but stuck badly from past two
days.
Trying to get it done with IADSUser.ChangePassword, thats
throwing error on password policy. So....that way of
authenticating is not being considered though I modified
the security policies to satisify the program to function.

Sub AuthenticateUser()
' VB . Project References : Active DS Type Librabry, ADO
' "Courtesy URL : http://builder.com.com/5100-6388-1045387-
2.html"
Dim oRootDSE As IADs
Dim oDSObj As IADsOpenDSObject
Dim oAuth As IADsContainer
Dim oUser As IADsUser
Dim strUsername As String, strNamingContext As String,
strPassword As String, strUserADSPath As String
Dim blnUserExists As Boolean

Dim adoConnection As New ADODB.Connection
Dim adoRecordset As New ADODB.Recordset
Dim strServerName As String

'test.com : Active directory domain on my system which is
AD domain controller too!
strServerName = "my-system-name.test.com:389/"
strUsername = "test-user-name" '<somedomain>\test-user-
name : domain name is not necessary
strPassword = "test-password"

Set oRootDSE = GetObject("LDAP://" & strServerName
& "RootDSE")
strNamingContext = strServerName & oRootDSE.Get
("defaultNamingContext")
Set oRootDSE = Nothing

strUserADSPath = ""
blnUserExists = False
adoConnection.Provider = "ADSDSOObject"

Set adoRecordset = adoConnection.Execute("<LDAP://" &
strNamingContext & ">;(sAMAccountName=" & strUsername
& ");AdsPath, cn")
If adoRecordset.RecordCount = 0 Then
Debug.Print Now() & " - User Name " & strUsername
& " not exists in the directory."
Else
Debug.Print Now() & " - User Name " & strUsername
& " exists in the directory."
strUserADSPath = adoRecordset.Fields
("ADSPATH").Value
blnUserExists = True
End If
adoRecordset.Close
Set adoRecordset = Nothing
adoConnection.Close
Set adoConnection = Nothing

If Not blnUserExists Then Exit Sub

Set oUser = GetObject(strUserADSPath)
Debug.Print "Account Disabled = " &
oUser.AccountDisabled
' FYI If disabled = true then exit sub

Set oDSObj = GetObject("LDAP:")
Set oAuth = oDSObj.OpenDSObject("LDAP://" &
strNamingContext, strUsername, strPassword,
ADS_SECURE_AUTHENTICATION)
' THIS LINE IS THE CULPRIT LINE THAT IS WORKING FINE
IN VB BUT FAILING WHEN THE SAME CODE TAKEN TO ASP WITH
APPRIOPRIATE CONSTANT VALUES SET
e.g.,ADS_SECURE_AUTHENTICATION
' WHAT IS THAT REASON THAT IS MAKING IT FAIL?????
PLEASE LET ME KNOW ASAP??
THE ERROR NUMBER : -2147016662 is being returned always
for ASP

If Not oAuth Is Nothing Then
MsgBox "Authentication Success", vbInformation
Set oAuth = Nothing
End If

Exit Sub

Err_Hnd:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
' Equivalent ASP Code

Sub AuthenticateUser(strUsername, strPassword)

on error resume next

ADS_SECURE_AUTHENTICATION = 1
ADS_SERVER_BIND = 512
strServerName = "my-system-
name.test.com:389/"
strUsername = "test-user-
name" '<somedomain>\test-user-name : domain name is not
necessary
strPassword = "test-password"
Set oRootDSE = GetObject("LDAP://" &
strServerName & "RootDSE")
strNamingContext = strServerName &
oRootDSE.Get("defaultNamingContext")
Set oRootDSE = Nothing
Response.Write "<BR> strNamingContext = "
& strNamingContext

strUserADSPath = ""
blnUserExists = False
set oADOConn = Server.CreateObject
("ADODB.CONNECTION")
set oADORs = Server.CreateObject
("ADODB.Recordset")
oADOConn.Provider = "ADSDSOObject"
oADOConn.Open
Set oADORs = oADOConn.Execute("<LDAP://" &
strNamingContext & ">;(sAMAccountName=" & strUsername
& ");AdsPath, cn")
If oADORs.RecordCount = 0 Then
Response.Write "<BR> " & Now() & " -
User Name <B>" & strUsername & "</B> not exists in the
active directory."
Else
Response.Write "<BR> " & Now() & " -
User Name <B>" & strUsername & "</B> exists in the active
directory."
strUserADSPath = oADORs.Fields
("ADSPATH").Value
blnUserExists = True
End If
oADORs.Close
Set oADORs = Nothing
oADOConn.Close
Set oADOConn = Nothing

If Not blnUserExists Then Exit Sub

Set oUser = GetObject(strUserADSPath)
Response.Write "<BR> Account Disabled = "
& oUser.AccountDisabled

Set oDSObj = GetObject("LDAP:")
Set oAuth = oDSObj.OpenDSObject("LDAP://"
& strNamingContext, strUsername, strPassword,
ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
' THIS LINE IS THE CULPRIT LINE THAT IS WORKING FINE
IN VB BUT FAILING WHEN THE SAME CODE TAKEN TO ASP WITH
APPRIOPRIATE CONSTANT VALUES SET
e.g.,ADS_SECURE_AUTHENTICATION
' WHAT IS THAT REASON THAT IS MAKING IT FAIL?????
PLEASE LET ME KNOW ASAP??
THE ERROR NUMBER : -2147016662 is being returned always
for ASP
if err.number <> 0 then
Response.Write "<BR>
Authentication Failed with Error Number = " & err.number

exit sub
end if
If Not oAuth Is Nothing Then
Response.Write "<BR> Authentication
Success"
Set oAuth = Nothing
End If

End sub

Suggestions please!

Thanks in advance!

Regards
Srinivas
Jul 19 '05 #1
0 1730

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: t.schwenk | last post by:
hi ng! in our intranet i try to get the users full name from ADSI. so i connect to a ad-provider with an enforced admin-logon (see ms knowledge-base 'LoginAdmin.dll') like that: Set objLogon...
9
by: Sophia | last post by:
I need to authenticate users to enter in a NTLM-protected virtual directory, but I can't pop up a NT-login dialogue box - I can only do a web-based username/password form (my client is a...
2
by: Christopher Johannsen | last post by:
Good Day: I am working on building a tool Using ASP/COM & IIS5.1 for a non-administrative technical support team to change domain passwords for users. I have the basic interface built and...
2
by: Enigma Webmaster | last post by:
Hi All, We've written a couple of functions which, when run in VB6 work fine and allow AD users to be updated. When we include the code into an ASP Page and try and update a users information...
1
by: HridayNarayan Rai | last post by:
This is hriday, wants to create an asp.net web page using c#. I want the validation, account creation, account updation, and account deletion of my user should happen using the active directory...
2
by: YRao | last post by:
I am going to create intranet application using Windows Authentication using C# asp.net I am having following problem: 1 setting windows Authentication, it will validate for all users, user...
8
by: msnews.microsoft.com | last post by:
I have ADSI code that I can make work at the command line. I cannot in any way get it to work in asp.net. Even using Windows authentication, impersonation on, and providing the credentials...
1
by: andy | last post by:
Has anyone ever experienced any problems authenticating with an ADSI application where after so long it stops responding. I can not track down what is causing the problem. I have a login page that...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.