Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET LDAP
Hi All,
 
I have a requirement where I need to authenticate a user using his LDAP username and password and once the user is authenticated I want to add the credentials of the user to a XML tag so that next time the log in can be more unique considering the performance. I have search several threads on it however I am still bit confused how to approach towards this.
Can anyone please give me any idea regarding the same ?
Thank you !
Posted 7-Feb-13 21:16pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The below code is for the LDAP authentication.
Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
        Dim Success As Boolean = False
        Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)
        Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
        Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel
        Try
            Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
            Success = Not (Results Is Nothing)
        Catch
            Success = False
        End Try
        Return Success
    End Function
 
Pass the required variable s as below
  If ValidateActiveDirectoryLogin("DOMAINNAME", Login1.UserName, Login1.Password) Then
        'do something

          Label1.Text = "Pass"
        Else
        lbl_msg.Text = "Login Failed"
        End If
 

The above code is quite fast, I dont think you would require to store it in XML and moreover, most of the ActiveDirectory services use a password expiration, so if security is a concern then authenticate on every login.
  Permalink  
Comments
Taresh Uppal at 11-Feb-13 7:06am
   
Actually Ineeded the XML coz there will be two kinds of user..One having read only access to my app and other having read and write both. So to check the users of each kind I need to keep one of the user's data into the xml on the project itself So that I can differentiate easily and make my choices according to it.
Anyways thanx for the link. It worked for me and I have coded the xml part too. Thanx again !
joe_j at 11-Feb-13 10:05am
   
your welcome and happy that it helped you. happy coding

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100