pGina.Plugin.LocalMachine.LocalAccount.CreateOrGetUserPrincipal C# (CSharp) Method

CreateOrGetUserPrincipal() private method

private CreateOrGetUserPrincipal ( UserInformation userInfo ) : System.DirectoryServices.AccountManagement.UserPrincipal
userInfo pGina.Shared.Types.UserInformation
return System.DirectoryServices.AccountManagement.UserPrincipal
        private UserPrincipal CreateOrGetUserPrincipal(UserInformation userInfo)
        {
            UserPrincipal user = null;
            if ( ! LocalAccount.UserExists(userInfo.Username) )
            {
                // See note about MS bug in CreateOrGetGroupPrincipal to understand the mix of DE/Principal here:
                using (user = new UserPrincipal(m_machinePrincipal))
                {
                    user.Name = userInfo.Username;
                    user.SetPassword(userInfo.Password);
                    user.Description = "pGina created";
                    userInfo.Description = user.Description;
                    if (userInfo.PasswordEXP)
                        user.ExpirePasswordNow();
                    user.Save();

                    // Sync via DE
                    SyncUserPrincipalInfo(userInfo);

                    // We have to re-fetch to get changes made via underlying DE
                    return GetUserPrincipal(user.Name);
                }
            }

            user = GetUserPrincipal(userInfo.Username);
            if (user == null)
                m_logger.ErrorFormat("Unable to get user principal for account that apparently exists: {0}", userInfo.Username);

            return user;
        }