Jump to content

Recommended Posts

Posted

Hi all,

 

Had the dreaded issue of students getting cover usernames/passwords last week, so after some work, I came up with a powershell script to reset our guest accounts passwords, write these to a file, and a webpage to render the results.

Reset.ps1

function GET-NewPassword() {
[int32[]]$ArrayofAscii=26,97,26,65,10,48,15,33
# Complexity can be from 1 - 4 with the results being
# 1 - Pure lowercase Ascii
# 2 - Mix Uppercase and Lowercase Ascii
# 3 - Ascii Upper/Lower with Numbers
# 4 - Ascii Upper/Lower with Numbers and Punctuation
$Complexity=3
# Password Length can be from 1 to as Crazy as you want
#
$PasswordLength=5
$NewPassword=$NULL
Foreach ($counter in 1..$PasswordLength) {
$pickSet=(GET-Random $complexity)*2
$NewPassword=$NewPassword+[char]((get-random $ArrayOfAscii[$pickset])+$ArrayOfAscii[$pickset+1])
}
Return $NewPassword
}

Import-Csv c:\reset-pass\users.csv | Foreach-Object {
   $rand = New-Object System.Random
   $NewPassword = Get-NewPassword
   New-Object PSObject -Property @{Username = $_.PSObject.Properties['Username'].Value; Type = $_.PSObject.Properties['Type'].Value; Password = $NewPassword; Date = Get-Date }
   Set-ADAccountPassword -Identity $_.PSObject.Properties['Username'].Value -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $NewPassword -Force)
} | Export-Csv \\server\path\users2.csv -NoTypeInformation

I set a scheduled task to run this powershell script each sunday, it will reset all the csv's users to a new password, and write a new csv on our webserver with the passwords in.

 

The csv used contains a list of usernames, and a type, e.g.

Username,Type
cover1,cover
cover2,cover
cover3,cover
cover4,cover
guest1,guest
guest2,guest
guest3,guest
guest4,guest

 

You get a file out like this

"Username","Password","Type","Date"
"cover1","BWOxv","cover","11/05/2015 16:11:48"
"cover2","dKYGa","cover","11/05/2015 16:11:54"
"cover3","wa4xe","cover","11/05/2015 16:11:54"
"cover4","5z6u8","cover","11/05/2015 16:11:54"

 

 

The folder the script writes to is NTFS protected to prevent unauthorised access, and the site uses Kerberos/NTLM auth to restrict it to staff.

 

The webpage uses jquery, and https://code.google.com/p/jquerycsvtotable/

 





   
   Guest Logons - Crickhowell High School
   
   
   
   
   
   <br />
        #CSVTable table {<br />
            border: solid 1px #ddd;<br />
            padding: 0;<br />
            margin: 0 auto;<br />
            border-collapse: collapse;<br />
        }<br />
<br />
            #CSVTable table td {<br />
                border-bottom: solid 1px #ddd;<br />
                border-right: solid 1px #ddd;<br />
                padding: 2px 10px;<br />
            }<br />
<br />
            #CSVTable table th {<br />
                border-bottom: solid 1px #ddd;<br />
                border-right: solid 1px #ddd;<br />
                padding: 2px 10px;<br />
                text-align: center;<br />
            }<br />
<br />
            #CSVTable table td:nth-of-type(1), #CSVTable table td:nth-of-type(2) {<br />
                font-family: 'Lucida Console';<br />
            }<br />
    


       
                       Guest Logon Usernames/Passwords
                       Valid until Sunday @ 4pm
                       
                       <br />
                            $(function () {<br />
                                $('#CSVTable').CSVToTable('users2.csv');<br />
                            });<br />
                        
       


 

You will need a Windows 2012 R2 AD DC to run the script, and set it to run as administrator in task schedular

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...