C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Authenticate user against active directory


Posted Date: 24 May 2008    Resource Type: Code Snippets    Category: Active Directory
Author: Praveena kandhiMember Level: Gold    
Rating: Points: 10



Public Function IsAuthenticated(ByVal username As String, ByVal pwd As String) As Boolean

Dim entry As DirectoryEntry = New DirectoryEntry(_path, username, pwd)
entry.AuthenticationType = AuthenticationTypes.Secure
entry.Path = _path

Try
'Bind to the native AdsObject to force authentication.

Dim obj As Object = entry.NativeObject
Dim search As DirectorySearcher = New DirectorySearcher(entry)


search.Filter = "(sAMAccountName=" & username & ")"



search.PropertiesToLoad.Add("cn")
search.PropertiesToLoad.Add("givenName")

Dim result As SearchResult = search.FindOne()
Dim info As DirectoryEntry = result.GetDirectoryEntry
' Label4.Text=CType(info.Properties("displayName").?? String.Empty, String)

If (result Is Nothing) Then
Return False

End If




'Update the new path to the user in the directory.
_path = result.Path
_filterAttribute = CType(result.Properties("cn")(0), String)
'_filterAttribute = CType(result.Properties("givenName")(1), String)


Catch ex As Exception
Throw New Exception("Error authenticating user. " & ex.Message)
End Try
' WriteLine(_filterAttribute)

Return True

End Function




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: what are the scopes of an assembly
Previous Resource: How to reset the drop down list using java script
Return to Discussion Resource Index
Post New Resource
Category: Active Directory


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use