CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Verifying Login username and password using acitve directory services

    Hi!
    I was trying to verify login information of a user to access a web page using active directory services using a code like this

    string Path="WinNT://DomainName";

    DirectoryEntry entry = new System.DirectoryServices.DirectoryEntryPath,UsrName,Password);
    Try{
    foreach(DirectoryEntry child in entry.Children)
    {
    if (child.Name.ToUpper()==UsrName.ToUpper() )
    {return true;}
    return false;
    }
    }
    catch (Exception et)
    {ErrLbl.Text="<strong>" + usrs + " " + et.Message + "</strong>";
    return false;
    }

    which should create the directory entry object and return the child entries
    but I am getting this error

    Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again


    Could anyone please let me know what is going wrong or is there any other way to verify user name and passwords.

    I did search the net where there is code using Directorysearcher
    which for me is also giving another error like
    Provider path does not exist or provider path does not allow searching.
    which again doesn't make sence as this path is a valid path.

    Can anyone Please help me.

    Your help is much appreciated.
    Nalina
    Last edited by iranew; July 28th, 2004 at 08:12 PM.

  2. #2
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    an excerpt from my article...

    Implementing Integrated Authentication
    Microsoft .NET provides WindowsIdentity class located in System.Security.Principal namespace. The class WindowsIdentity represents the current windows user. Lets obtain the current windows user name:

    //declare the class instance and get current user.
    WindowsIdentity m_WinID = WindowsIdentity.GetCurrent();

    GetCurrent Methode returns a WindowsIdentity object that represents the current Windows user.

    If the application creates log files, or simply traces the application, it may need to know which user is currently executing the application. Lets obtain the current user name

    //get the user name

    string m_szUserName = m_WinID.Name;

    Similarly, we can get the authentication type for this user. Basic authentication, NTLM, Kerberos, and Passport are examples of authentication types. As Microsoft implies, authentication type is typically NTLM for WindowsIdentity objects.

    //get the authentication type

    TBAuthType.Text = m_WinID.AuthenticationType;

    Now, based upon the user account, a developer can decrease the functionality of the application or close the application or allow running the application.

    private void UserStatus()
    {
    //declare the class instance and get current user.
    WindowsIdentity m_WinID = WindowsIdentity.GetCurrent();

    //check if the user account is anonymous account?
    if(m_WinID.IsAnonymous)
    Application.Exit();

    //check if the user account is authenticated by windows or a system account
    else if(m_WinID.IsAuthenticated || m_WinID.IsSystem)
    return;

    //check if the user account is a Guest account
    else if(m_WinID.IsGuest)

    //remove a TabPage from Property sheet
    TCRegTest.TabPages.Remove(TPRegAdd);
    }

    [edit]] formatting lost...
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured