Creativity and Innovation

Just another WordPress.com weblog

Authenticate User and Password with Active Directory

Leave a comment


Option Explicit

Sub Test()
Dim status As Boolean

status = authenticateWindowsLogin(“GANESH”, “pass@1273”, “home”)

If (status = True) Then
Debug.Print “User is authenticated successfully”
Else
Debug.Print “User is not authenticated”
End If

End Sub

‘Authenticates user and password entered with Active Directory.
Private Function authenticateWindowsLogin(ByVal strUserName As String, ByVal strpassword As String, ByVal strDomain As String) As Boolean

On Error GoTo ERROR_BLOCK

Dim oADsObject As Object, oADsNamespace As Object
Dim strADsPath As String

strADsPath = “WinNT://” & strDomain
Set oADsObject = GetObject(strADsPath)
Set oADsNamespace = GetObject(“WinNT:”)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain & “\” & strUserName, strpassword, 0)

authenticateWindowsLogin = True ‘ACCESS GRANTED

Exit_BLOCK:
On Error Resume Next
Exit Function

ERROR_BLOCK:
Debug.Print “Error Source:<” & Err.Source & “>,Function Name:”
Debug.Print “Error Number:<” & Err.Number & “>,Error Description:<” & Err.Description & “>”
authenticateWindowsLogin = False ‘ACCESS DENIED
Err.Clear
Resume Exit_BLOCK
End Function

Advertisements

Author: Ganesh

Ganesh Bhagat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s