From: John Beschler on
I am developing a WEB-based employee evaluation app that reuires the
supervisor and employee have a "face-to-face". To confirm that this has been
accomplished, I want to have a form that the employee and the supervisor will
both "sign" electronically during the same session. To do that, obviously, I
need to validate both users.

My plan is to allow the users to enter their AD usernames/passwords and
validate them against the domain. I have found a few examples of how to do
that using VB but none using C#. Can anyone help me with this please?

Thanks,
John
From: Mark Rae [MVP] on
"John Beschler" <JohnBeschler(a)discussions.microsoft.com> wrote in message
news:64324E0E-A6BF-4906-AB43-320E11933622(a)microsoft.com...

> My plan is to allow the users to enter their AD usernames/passwords and
> validate them against the domain. I have found a few examples of how to do
> that using VB but none using C#. Can anyone help me with this please?

using System;
using System.Collections.Generic;
using System.DirectoryServices;

/// <summary>
/// Validates a logon request against the current domain
/// </summary>
/// <param name="pstrUser">User account without domain name</param>
/// <param name="pstrPassword">Password</param>
/// <returns>Boolean</returns>
bool Logon(string pstrUser, string pstrPassword)
{
try
{
using (DirectoryEntry objADEntry = new DirectoryEntry("LDAP://" +
System.Environment.UserDomainName, pstrUser, pstrPassword))
{
return !objADEntry.NativeObject.Equals(null);
}
}
catch (System.Runtime.InteropServices.COMException)
{
return false;
}
catch (Exception)
{
throw;
}
}


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: John Beschler on
Thanks Mark. That worked perfectly!

"Mark Rae [MVP]" wrote:

> "John Beschler" <JohnBeschler(a)discussions.microsoft.com> wrote in message
> news:64324E0E-A6BF-4906-AB43-320E11933622(a)microsoft.com...
>
> > My plan is to allow the users to enter their AD usernames/passwords and
> > validate them against the domain. I have found a few examples of how to do
> > that using VB but none using C#. Can anyone help me with this please?
>
> using System;
> using System.Collections.Generic;
> using System.DirectoryServices;
>
> /// <summary>
> /// Validates a logon request against the current domain
> /// </summary>
> /// <param name="pstrUser">User account without domain name</param>
> /// <param name="pstrPassword">Password</param>
> /// <returns>Boolean</returns>
> bool Logon(string pstrUser, string pstrPassword)
> {
> try
> {
> using (DirectoryEntry objADEntry = new DirectoryEntry("LDAP://" +
> System.Environment.UserDomainName, pstrUser, pstrPassword))
> {
> return !objADEntry.NativeObject.Equals(null);
> }
> }
> catch (System.Runtime.InteropServices.COMException)
> {
> return false;
> }
> catch (Exception)
> {
> throw;
> }
> }
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>