Bugra Postaci's Blog

All my posts are provided "AS IS" with no warranties, and confer no rights.

  • Home
  • About
  • Privacy
Posts Comments
  • Sharepoint
    • Sharepoint 2010
    • SharePoint 2013
    • Sharepoint Tips & Tricks
    • SharePoint 2016
    • Sharepoint Tools
  • ASP.NET
  • C#
    • Tips & Tricks
  • Uncategorized

c# LDAP check user is locked or not

14/04/2010 Leave a comment

How to check an active directory user is locked or not using c#:

//SOME GLOBAL DEFINITION
public const string userdn = "10.0.0.4/CN=MyUserAcc,OU=PORTAL,DC=TEST,DC=entst,DC=local";
public const string DCUserName = "TEST\\admin"; //Admin Account for query
public const string DCPassWord = "secret";

//USAGE
bool value= LDAPHelper.Users.IsLocked(userdn, DCUserName, DCPassWord);

//CODE
public static bool IsLocked(string userDn,string adminuser,string adminpass )
{
    try
    {
        DirectoryEntry user = new DirectoryEntry(userDn,adminuser,adminpass);
        string attribName = "msDS-User-Account-Control-Computed";
        user.RefreshCache(new string[] { attribName });
        const int UF_LOCKOUT = 0x0010;
        int userFlags = (int)user.Properties[attribName].Value;
        if ( (userFlags & UF_LOCKOUT) == UF_LOCKOUT)
        {
            // if this is the case, the account is locked out
            return true;
        }
        return false;
    }
    catch
    {
        return false;
    }
}

Filed under C# Tagged with Active Directory, DC, LDAP, lockout, msDS-User-Account-Control-Computed, UF_LOCKOUT

RSS Register

  • RSS - Posts
  • RSS - Comments

Search

Inside my brain

2010 2013 AAM Access Denied AD ASP.NET Authentication Backup C# configuration Content Content-type CU Cumulative Database Delete deployment enum Error Excel Feature GAC GC Http HttpHandler IE8 IIS LDAP list Lock() Log meeting Moss2007 Moss 2007 mysite Ninject NTLM Performance PowerShell problem Profile RBS Redirection request Search security server Service Service Pack session Sharepoint Sharepoint 2007 Sharepoint 2010 Sharepoint2010 SharePoint 2013 Site SP1 SP2 SPS2010 SPS2013 SQL stsadm Support Supportability Sync Syncronization TimerJob tools ULS UPA Update user Web Webpart Workflow

Categories

  • .Net Tools (6)
  • ASP.NET (34)
  • C# (32)
  • Coolite (1)
  • Debugging (1)
  • Design Patterns (1)
  • IIS (4)
  • Microsoft Support (1)
  • Powershell (2)
  • Sharepoint (105)
  • Sharepoint 2010 (89)
  • SharePoint 2013 (54)
  • SharePoint 2016 (9)
  • SharePoint 2019 (3)
  • SharePoint Online (5)
  • Sharepoint Tips & Tricks (20)
  • Sharepoint Tools (7)
  • System (2)
  • T-SQL (5)
  • Tips & Tricks (10)
  • Uncategorized (30)
  • Visual Studio IDE (4)

Top Posts

  • Stop SharePoint Completely or stopping the farm
  • Error acces to registry key when installing RBS.msi
  • If you are getting "Method not found" (MissingMethodException) error in SharePoint 2010
  • Sharepoint RunWithElevatedPrivileges and Access Denied error
  • How to send Real Meeting Request from Sharepoint 2010 - part 1
  • c# FileLock - If you need to lock a file for temporary purpose.
  • Clean up - Search Service Application in SharePoint 2013
  • Resolving error of "is an unexpected token. The expected token is xx or xx . Line xx ,Position xx for Sharepoint 2007
  • Unable to delete Search Service Application (SSA) in SharePoint 2010
  • The SPListItem being updated was not retrieved with all taxonomy fields

My Recents

  • Anjular.js fragment identifier “#” hash issue with SharePoint 2019 Modern UI
  • About future of the Content Deployment feature for SharePoint 2019
  • Unable to open documents using direct links from SharePoint 2019
  • An Issue with changing ProxyGroup for a ServiceApplication in SharePoint
  • Redirecting http to https in SharePoint with AAM

Archives

  • November 2019 (2)
  • August 2019 (2)
  • July 2019 (2)
  • June 2019 (1)
  • May 2019 (1)
  • April 2019 (2)
  • March 2019 (2)
  • January 2019 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (1)
  • January 2018 (1)
  • December 2017 (1)
  • November 2017 (1)
  • July 2017 (1)
  • June 2017 (3)
  • May 2017 (1)
  • February 2017 (2)
  • May 2016 (1)
  • March 2016 (1)
  • February 2016 (1)
  • December 2015 (1)
  • November 2015 (1)
  • October 2015 (2)
  • August 2015 (3)
  • July 2015 (1)
  • June 2015 (4)
  • May 2015 (2)
  • April 2015 (1)
  • March 2015 (1)
  • February 2015 (3)
  • January 2015 (1)
  • December 2014 (3)
  • October 2014 (3)
  • August 2014 (6)
  • July 2014 (2)
  • May 2014 (5)
  • April 2014 (5)
  • March 2014 (2)
  • February 2014 (17)
  • December 2013 (2)
  • November 2013 (3)
  • October 2013 (5)
  • August 2013 (1)
  • July 2013 (3)
  • June 2013 (4)
  • May 2013 (2)
  • April 2013 (1)
  • March 2013 (3)
  • February 2013 (3)
  • January 2013 (4)
  • December 2012 (1)
  • November 2012 (4)
  • October 2012 (3)
  • September 2012 (2)
  • August 2012 (3)
  • July 2012 (5)
  • June 2012 (2)
  • May 2012 (3)
  • April 2012 (9)
  • March 2012 (7)
  • February 2012 (10)
  • January 2012 (8)
  • December 2011 (8)
  • November 2011 (2)
  • October 2011 (11)
  • September 2011 (10)
  • August 2011 (5)
  • July 2011 (7)
  • June 2011 (13)
  • May 2011 (2)
  • April 2011 (11)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (6)
  • December 2010 (4)
  • November 2010 (4)
  • October 2010 (14)
  • September 2010 (5)
  • August 2010 (3)
  • April 2010 (9)
  • March 2010 (7)
  • February 2010 (10)
  • January 2010 (42)
  • December 2009 (3)
  • November 2009 (9)

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy