Ejemplo n.º 1
0
        /// <summary>
        /// Expires the specified user or computer's password, forcing it to be required to be reset.
        /// </summary>
        /// <param name="name">The unique identifier of the user or computer.</param>
        /// <returns>True if the password was expired successfully, false otherwise.</returns>
        public static Boolean ExpirePassword(string name)
        {
            Boolean result = false;

            try
            {
                Principal p = Principal.FindByIdentity(GetPrincipalContext(), name);

                if ((p != null) && (p is UserPrincipal))
                {
                    UserPrincipal u = p as UserPrincipal;
                    u.ExpirePasswordNow();
                    u.Save();
                    result = true;
                }
                else if ((p != null) && (p is ComputerPrincipal))
                {
                    ComputerPrincipal c = p as ComputerPrincipal;
                    c.ExpirePasswordNow();
                    c.Save();
                    result = true;
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }