Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authenticate to App using AD 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm using VB.net 2010. I'm coming off of VB6. In my VB6 apps I would have the users login to the app using their AD credentials, that way they can use the same password as they do when they log into their machine. Now I'm trying to do the same thing with VB 2010 but can't seem to find any good examples of code. Most of the examples are in C#. Can someone point me in the right direction.

Any help would be appreciated

Thanks in advance

 
This code work in VB 2008, so it should work in 2010 as well:

Code:
    Private Function ActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean

        Dim bRetVal As Boolean = False

        Dim deThisUser As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)

        Dim dsThisSearcher As New System.DirectoryServices.DirectorySearcher(deThisUser)

        dsThisSearcher.SearchScope = DirectoryServices.SearchScope.OneLevel

        Try
            Dim srFound As System.DirectoryServices.SearchResult = dsThisSearcher.FindOne

            bRetVal = Not (srFound Is Nothing)

        Catch ex As Exception

            bRetVal = False

        End Try

        Return bRetVal

    End Function

Call it like this:

Code:
        If ActiveDirectoryLogin("<<Put your FQDN here>>", txtUserName.Text, txtPassword.Text) Then
            MsgBox("Authenticated")
        Else
            MsgBox("Not Authenticated")
        End If

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top