Click to See Complete Forum and Search --> : Verifying Login username and password using acitve directory services


iranew
July 28th, 2004, 08:06 PM
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

Andy Tacker
July 29th, 2004, 03:32 AM
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...