Checking User Group in Active Directory using VB.net

Hi

i am new to .net and active directory.

i need to validate user in Active directory.

my input data is Domain name , Username and groupName and i won't pass password


private function chechkUser(ByVal domain As String, ByVal username As String, ByVal GroupName As String) As Boolean

if username is found in active directory

chechkUser = true
else
chechkUser = false

end function

how to resolve this?
can any send VB.net code for this requirement?
thanx in advance

-naren

[569 byte] By [narend] at [2007-12-24]
# 1

Pretty easy in VS2005

If My.User.IsInRole("Group Name") Then
Return True
Else
Return False
End If

VS2003 takes a little more work. Post again if you need an example for the older version.

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Hi thanks a lot for your reply.....it works for group

but i need validate along with Domain and user name as well

eg..

if Domain="mydomain" and groupname= "mygroupname" and username="myuser" then

return true

else

return false

end if

how to do that VS2005?

Thanks in advance

narend at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Hi ,

is this correct?

If System.Environment.UserDomainName = "DomainName" And My.User.IsInRole("GroupName") Then

MsgBox("True")

Else

MsgBox("false")

End If

narend at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Sorry, didn't read you close enough... That's getting pretty complex and I think you'll need to use LDAP queries to get your answer.

You can add a reference to System.DirectoryServices to get some objects that facilitate Active Directory lookups.

Keep in mind that a lot of this will depend on the security level of the user running the application... Cross domain lookups will need to be configured and allowed in AD as well.

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

this following statement works for me..

i dont know whether it is correct approach

This statement validates my domain,group and user

If System.Environment.UserDomainName = "DomainName" And My.User.IsInRole("GroupName") Then

MsgBox("True")

Else

MsgBox("false")

End If

narend at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

Yeah, that works for the current user. I just noticed that your desired function contains the user and domain as parameters so I wasn't sure if you wanted to check for users or domains other than the current.

If all you need to check are the current logged on user in their current domain then you've got your answer! If you want to check any user in any domain that you've got permission to query than you'll need to use LDAP.

Good Luck

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

thanks.

i need to check only for the current logged on user

narend at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...