Creativity and Innovation

Just another 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”
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


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

On Error Resume Next
Exit Function

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


Author: Ganesh

Ganesh Bhagat

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s