Active Directory AD authentication in Classic ASP

Function UserOkRichStyle(szUserName,szPassword) 'True if success; false otherwise

                

                Set oCommand = CreateObject("ADODB.Command")

                Set oConnection = CreateObject("ADODB.Connection")

    on error resume next

                ' Get the Configuration Naming Context.

                Set oRootDSE = GetObject("LDAP://RootDSE")

                varDomainNC = oRootDSE.Get("defaultNamingContext")

                ' Open the Connection

                oConnection.Provider = "ADsDSOObject"

                oConnection.Properties("User ID") = "YOUR_DOMAIN_HERE\" & szUserName

    oConnection.Properties("Password") = szPassword

                oConnection.Open "ADs Provider"

                ' Build the query to find the user based on their alias.

                strQuery = "<LDAP://" & varDomainNC & ">;(&(objectClass=user)(objectCategory=person)" & _

                           "(samAccountName=" & Trim(szUserName) & "));adspath;subtree"

                'response.write strquery

                oCommand.ActiveConnection = oConnection

                oCommand.CommandText = strQuery

                on error resume next

                Set RS = oCommand.Execute

    'response.write " RS.RecordCount : " & RS.RecordCount & "<BR>"

                If RS.RecordCount = 0 Then

                                UserOkRichStyle =false

                Else

                UserOkRichStyle = true

    end if

end function

Password Dialog box sample

Public Class Form1

    Dim test As New CustomForm("workflow")

    Public Class CustomForm

        Inherits Form

        Property SecretPassword As String

        Property GrantAccess As Boolean

        Sub New(Password As String)

            GrantAccess = False

            Me.SecretPassword = Password

            Dim lbl As New Label

            lbl.Text = "Password"

            Me.Controls.Add(lbl)

            Me.Text = "***PASSWORD INPUT REQUIRED***"

            Dim frmSZ As New Size(400, 100)

            Me.Size = frmSZ

            Dim IBox As New TextBox

            AddHandler IBox.KeyDown, AddressOf TextBox1_KeyDown

            Dim ibox20 As New Point(100, 0)

            IBox.Location = ibox20

            IBox.PasswordChar = "*"

            Me.Controls.Add(IBox)

            Me.Show()

        End Sub

        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs)

            If e.KeyCode = Keys.KeyCode.Enter Then

                Try

                    Dim passswordInput As String = sender.text

                    If passswordInput = Me.SecretPassword Then

                        GrantAccess = True

                        Me.Dispose()

                    Else

                        MsgBox("Sorry the password you entered is not correct please try again. The password is case sensitive make sure your caps lock is not on.")

                    End If

                Catch ex As Exception

                End Try

            End If

        End Sub

    End Class

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        MsgBox(test.GrantAccess)

    End Sub

End Class

https://stackoverflow.com/questions/18834874/using-password-character-in-inputbox

x x