RE: Check If User Exists...

From: Grigs (Grigs_at_discussions.microsoft.com)
Date: 07/09/04


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


Relevant Pages

  • Re: priviledge escalation techniques
    ... you've all the tools you need, and you can install additional ones (to ... If I press that BEFORE login, a CLI as SYSTEM is started, I can launch ... If the network is switched, perhaps you need an ARP poisoning tool. ... switches) in such a way that you can fool an ARP poisoning attempt. ...
    (Pen-Test)
  • Re: Slow Login with Cached Credentials
    ... might relate to my issue of "Slow Login with Cached Credentials" ... Of course when they are on the network and there is a domain controller ... in the event log. ... REM Disconnect existing network mappings - do not prompt the user ...
    (microsoft.public.windowsxp.general)
  • Automatically Login to a Domain
    ... accessing network drives or print servers). ... after using the standard CE domain login dialog, ... The credential manager code is also shown at the bottom of this post: ... // setup the remote name which will be my domain name e.g. MYDOMAIN ...
    (microsoft.public.windowsce.app.development)
  • Re: Workstation Locked out!
    ... the domain Administrator account, ... Have you tried to log in with the local Administrator account using a blank ... When you go to the ctrl+alt+del login screen on the workstation and click ... I tried to connect an old XP pro box to the network using the connect ...
    (microsoft.public.windows.server.sbs)
  • Slow Login with Cached Credentials
    ... I am having an issue with many XP SP2 Dell Lattitude D6xx laptops. ... Of course when they are on the network and there is a domain controller ... All laptop users have both a login and logoff script (assigned via GPO to the ... REM Disconnect existing network mappings - do not prompt the user ...
    (microsoft.public.windowsxp.network_web)