Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kasper 9 posts 74 karma points
    Feb 08, 2016 @ 19:40
    Kasper
    0

    Hi,

    I want to disable all Umbraco users, that are inactive for a certain periode of time. Like 3 months etc. Is doesn't look like there are any login timestamps in the database. Users logins are registered in the logfiles.

    Is this the only way?

    I've created a small powershell snippet to extract user IDs of users logged in, and build up a query to disable all others.

    Is this really the only way?? (Works fine btw.)

    Script:

    $DiscoveredUserIds = @()
    $value = 0
    
    $LoginEvents = Get-ChildItem "UmbracoTraceLog.txt.2015-08-18" | Get-Content | Where { ($_).Contains("User Id:") }
    Foreach ($LoginEvent in $LoginEvents)
    {
        Write-Host "Testing $LoginEvent"
        $found = $LoginEvent -match '.*User Id: (\d+) logged in.*'
        if ($found) 
        {
            if ( [int]::TryParse( $matches[1], [ref]$value ) )
            {
                $DiscoveredUserIds += [int]$matches[1]
            }
        }
    }
    $ValidUsers = $DiscoveredUserIds | Sort-Object -Unique
    
    $Query = "UPDATE [umbracoUser] SET userDisabled = 1, userNoConsole = 1 WHERE id NOT IN (0,"+ ($ValidUsers -Join ",")+ ")"
    $Query
    

    Output

    PS E:\temp\kbrandenburg\umbracolog> C:\Users\kbrandenburg\Desktop\PowershellDisableUmbraco_users.ps1 Testing 2015-08-18 10:58:53,664 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 125] User Id: 5 logged in Testing 2015-08-18 13:04:14,037 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 5 logged in Testing 2015-08-18 13:07:26,456 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 67] User Id: 4 logged in Testing 2015-08-18 13:33:42,150 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 70] User Id: 4 logged in Testing 2015-08-18 13:40:16,132 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 32] User Id: 10 logged in Testing 2015-08-18 14:44:05,649 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 4 logged in UPDATE [umbracoUser] SET userDisabled = 1, userNoConsole = 1 WHERE id NOT IN (0,4,5,10)

  • Kasper 9 posts 74 karma points
    Feb 25, 2016 @ 13:07
    Kasper
    0

    no response, really??

  • Dave Woestenborghs 3259 posts 11059 karma points MVP 5x admin c-trib
    Feb 25, 2016 @ 13:24
    Dave Woestenborghs
    0

    Hi Kasper,

    Actually the umbracoUser table contains a column called [lastLoginDate]. This contains the last login date of the user.

    Dave

  • Kasper 9 posts 74 karma points
    Feb 25, 2016 @ 13:35
    Kasper
    0

    Ours do not, the in the columns in UmbracoUser

    [id] ,[userDisabled] ,[userNoConsole] ,[userType] ,[startStructureID] ,[startMediaID] ,[userName] ,[userLogin] ,[userPassword] ,[userEmail] ,[userDefaultPermissions] ,[userLanguage] ,[defaultToLiveEditing]

  • Dave Woestenborghs 3259 posts 11059 karma points MVP 5x admin c-trib
    Feb 25, 2016 @ 13:39
    Dave Woestenborghs
    0

    Looking at that table it seems you are version lower than 7 because the defaultToLiveEditing column has been removed in that version.

    I think in old versions there was also a table called umbracoUserLogins

    Maybe you can get the information from there. I think loggins were also logged in the umbracoLog table in older versions. Maybe it's worth checking that as well.

    Dave

  • Kasper 9 posts 74 karma points
    Feb 25, 2016 @ 13:43
    Kasper
    0

    umbracoUserLogins is empty. Found a github request, on that where the dev-team explained it was deprecated table, to be removed in future versions.

    I'm fine with traversing logfiles for users, but how about actually disabling them. Doing a SQL query into the DB behind the app seems like a nasty solution. Is there an API i can use?

  • Dave Woestenborghs 3259 posts 11059 karma points MVP 5x admin c-trib
    Feb 25, 2016 @ 13:44
    Dave Woestenborghs
    0

    What version are you using ? Depends on what version you are using.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft