pGina.Plugin.LocalMachine.LocalAccount.GetUserPrincipal C# (CSharp) Метод

GetUserPrincipal() публичный статический Метод

public static GetUserPrincipal ( SecurityIdentifier sid ) : System.DirectoryServices.AccountManagement.UserPrincipal
sid SecurityIdentifier
Результат System.DirectoryServices.AccountManagement.UserPrincipal
        public static UserPrincipal GetUserPrincipal(SecurityIdentifier sid)
        {
            // This could be updated to use PrincipalSearcher, but the method is currently
            // unused.
            return UserPrincipal.FindByIdentity(m_machinePrincipal, IdentityType.Sid, sid.ToString());
        }

Same methods

LocalAccount::GetUserPrincipal ( string username ) : System.DirectoryServices.AccountManagement.UserPrincipal

Usage Example

Пример #1
0
        public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
        {
            m_logger.Debug("ChangePassword()");

            // Verify the old password
            if (Abstractions.WindowsApi.pInvokes.ValidateCredentials(cpInfo.Username, cpInfo.OldPassword))
            {
                m_logger.DebugFormat("Authenticated via old password: {0}", cpInfo.Username);
            }
            else
            {
                return(new BooleanResult {
                    Success = false, Message = "Current password or username is not valid."
                });
            }

            using (UserPrincipal user = LocalAccount.GetUserPrincipal(cpInfo.Username))
            {
                if (user != null)
                {
                    m_logger.DebugFormat("Found principal, changing password for {0}", cpInfo.Username);
                    user.SetPassword(cpInfo.NewPassword);
                }
                else
                {
                    return(new BooleanResult {
                        Success = false, Message = "Local machine plugin internal error: directory entry not found."
                    });
                }
            }

            return(new BooleanResult {
                Success = true, Message = "Local password successfully changed."
            });
        }
All Usage Examples Of pGina.Plugin.LocalMachine.LocalAccount::GetUserPrincipal