Hi guys i need your help
can you explain this code for me the using the aspx.vb to write and i not understand can explain it to me pls?

Below is the code

Protected Sub Login_ImageButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_ImageButton.Click
        Dim loginId As String = usernameTextBox.Text.Trim
        Dim loginPwd As String = PasswordTextBox.Text.Trim
        Dim entry As New DirectoryEntry("LDAP://128.128.128.1", "mygroup\" & loginId, loginPwd)

Line #3 - DirectoryEntry provides programmatic access of directory services through LDAP.

It looks like that is tied in to some sort of authentication as adatapost indicated. LDAP is directory authentication protocol. Can you post more code?

It looks like that is tied in to some sort of authentication as adatapost indicated. LDAP is directory authentication protocol. Can you post more code?

Here are the complete code of it

Imports System.DirectoryServices

Partial Class Login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        usernameTextBox.Focus()
    End Sub

    Protected Sub Login_ImageButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_ImageButton.Click
        Dim loginId As String = usernameTextBox.Text.Trim
        Dim loginPwd As String = PasswordTextBox.Text.Trim
        Dim entry As New DirectoryEntry("LDAP://128.128.0.1", "mygroup\" & loginId, loginPwd)
        Try
            Dim obj As Object = entry.NativeObject
            Dim search As New DirectorySearcher(entry)
            search.Filter = "(SAMAccountName=" & loginId & ")"
            search.PropertiesToLoad.Add("displayName")
            search.PropertiesToLoad.Add("Title")
            Dim result As SearchResult = search.FindOne
            If result Is Nothing Then
                Response.Write("False")
            End If
            Dim tempUserName As String = CType(result.Properties("displayName")(0), String)
            Dim tempTitle As String = StrConv(CType(result.Properties("Title")(0), String), VbStrConv.ProperCase)
            Dim dashIndex As Integer = tempUserName.IndexOf("-")
            tempUserName = tempUserName.Substring(dashIndex + 1).Trim.ToUpper
            Session("UserName") = tempUserName
            Session("Title") = tempTitle
            Session("Auth") = True
            ClientScript.RegisterStartupScript(Me.GetType, "RefreshParent", "<script language='javascript'>RefreshParent()</script>")
            If Session("PreviousURL") = Nothing Then
                Response.Redirect("~/View.aspx")
            Else
                Response.Redirect("~/" + Session("PreviousURL"))
            End If
        Catch ex As Exception
            LoginError_Label.Text = "Unknown user name or bad password."
        End Try
    End Sub
End Class

That code is looking up a user in active directory to get their title and display name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.