AD User Login
protected void btnLogin_Click(object sender, EventArgs e)
{
string domainname = "domainname";
try
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainname))
{
// validate the credentials
bool isValid = pc.ValidateCredentials(txtUserName.Text.Trim(), txtPassword.Text.Trim());
if (isValid)
{
UserPrincipal user = UserPrincipal.FindByIdentity(pc, txtUserName.Text.Trim());
lblstatus.Text = "Welcome " + user.Name + ",";
}
else
{
lblstatus.Text = "Invalid Username or Password.";
}
}
}
catch (Exception ex)
{
lblstatus.Text = "Invalid Domain";
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string domainname = "domainname";
try
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainname))
{
// validate the credentials
bool isValid = pc.ValidateCredentials(txtUserName.Text.Trim(), txtPassword.Text.Trim());
if (isValid)
{
UserPrincipal user = UserPrincipal.FindByIdentity(pc, txtUserName.Text.Trim());
lblstatus.Text = "Welcome " + user.Name + ",";
}
else
{
lblstatus.Text = "Invalid Username or Password.";
}
}
}
catch (Exception ex)
{
lblstatus.Text = "Invalid Domain";
}
}
wow! this is great script! can someone find me its source please.
ReplyDelete