Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

The below code is for the LDAP authentication.
VB
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


VB
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.
 
Share this answer
 
Comments
Taresh Uppal 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900