RE: Check If User Exists...
From: Grigs (Grigs_at_discussions.microsoft.com)
Date: 07/09/04
- Next message: Patrick Steele [MVP]: "Re: Strings.. Objects or not???"
- Previous message: Jon Skeet [C# MVP]: "Re: Strings.. Objects or not???"
- In reply to: Grigs: "Check If User Exists..."
- Next in thread: sean: "RE: Check If User Exists..."
- Reply: sean: "RE: Check If User Exists..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Jul 2004 06:48:02 -0700
Well with further searching and testing I have figured out my own problem to what I figured was a simple problem. Here is the full code you would need to verify if a given "login name" is tied to any user in your network with VB.Net.
The loginame name passed in as a string. If it is a valid user's login name, then True will be returned, otherwise False. Be sure the change the NetworkName to your Network name. The sLoginName is not case sensitive.
You must add a Reference to the system.DirectoryServices .dll for this to work.
Private Function IsValidLoginName(ByVal sLoginName As String) As Boolean
' Search for a user with a given login name
Dim oDirEntry As New System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")
Dim oDirSearch As New System.DirectoryServices.DirectorySearcher(oDirEntry)
Dim oResult As System.DirectoryServices.SearchResult
oDirSearch.Filter = _
"(&(objectClass=user)(samaccountname=" & sLoginName & "))"
Try
oResult = oDirSearch.FindOne
IsValidLoginName = True
Catch e As Exception
IsValidLoginName = False
End Try
End Function
-- Thanx, Grigs "Grigs" wrote: > Hello, > > Long time coder, but Very very new to .Net and am wanting to add some code to an existing VB.Net app. > > I will be given a users login name and want to verify that it is still a valid login name. I assume I can do it through the System.DirectoryServices.DirectorySearcher object but tried a few things and didn't get it to work. (again, very new to .Net at least). > > I simply want to do some sort of search on the passed in "login name" and if that user is found then I continue. I have to believe this is only a couple lines of code. If the above class I mentioned is too bulky or someone has a better way, please send it. > > -- > Thanx, > Grigs
- Next message: Patrick Steele [MVP]: "Re: Strings.. Objects or not???"
- Previous message: Jon Skeet [C# MVP]: "Re: Strings.. Objects or not???"
- In reply to: Grigs: "Check If User Exists..."
- Next in thread: sean: "RE: Check If User Exists..."
- Reply: sean: "RE: Check If User Exists..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|