Skip to main content
Dear All,

I have tried the msdn code to authenticate the AD user. It is checking only the user name and password but not the domain. Anyone faced similar difficulties? If yes can you please share it?

Rgds,
Minor.
Are you using the .Net directory services? Why do you want to authenticate the user? Please give me some more info on what you want to achieve.
Yes. David.

I am using .Net Directory Services.

I have text boxes one each for domain, username and password.

1) If I give the correct domain, correct Username and password it is working fine.

2) If I give the wrong domain, correct Username and password then also it is working fine.

That's Why I felt it is not checking the domains.

My target is to authenticate the AD user respective to the domain before allowing him to enter into my site.

The following is the code.

Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain + "" + username
Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)
Try
Dim obj As Object = entry.NativeObject
Dim search As DirectorySearcher = New DirectorySearcher(entry)
search.Filter = "(sAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
_path = result.Path
_filterAttribute = CType(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " + ex.Message)
End Try
Return True
End Function
Hi,

I found a nice link that explains bind to AD w/script and disable/move users. Use the ADODB.Connection in VB and with a few minor changes you should be able to know if a user is valid, disabled etc.

http://www.codecomments.com/archive305-2004-12-351293.html

Regards,
David
Just curious...

My target is to authenticate the AD user respective to the domain before allowing him to enter into my site.

Why don't you just use 'Windows Integrated Authentication'?

Remember, if your users have to fill in usernames and passwords it will probably travel in clear text on the network.

Regards,
Ockert

Ok. But will the Windows integrated authentication concept work in internet?

Rgds,
Minor.
Absolutely.

Regards,
Ockert
Hi Ockert,

In additional to my below query, I want to have a secondary login concept also for my site.

I have many reasons to go for this secondary login concept.
1) Security.
2) Session handling.
3) Internet enabled.

Again I am repeating the problem I faced at the time of secondary login.

I am using .Net Directory Services.

I have text boxes one each for domain, username and password.

1) If I give the correct domain, correct Username and password it is working fine.

2) If I give the wrong domain, correct Username and password then also it is working fine.

That's Why I felt it is not checking the domains.

Rgds,
Minor.
I'm not an AD expert by any stretch of the imagination and this is actually not the forum for the problem you are experiencing BUT... maybe the .NET DirectoryServices class disregards the domain and work with the 'Default' domain your currently logged on to.

Regards,
Ockert
Thanks for your suggestion.
Although it is not related to K2.Net it is part of my application which I am concentrating to complete it by using K2.Net broadly.

Rgds,
Minor.

Reply