The Multifunctioning DBA

Aug 14 2009   8:56PM GMT

Random Password Script Powershell



Posted by: Colin Smith
Tags:
Database Administration
Passwords
Powershell
Windows Administration

I was recently asked if I could write a script that would create a random password based on a word list. The password needs to have a capital letter, a special character, and a number. The password also has to be made up of two seperate words that are in the word list.

my words.csv file is formatted as so

Number, Word

Here is what I did.

$symbols = “(“, “!”, “@”, “#”, “$”, “%”, “^”, “&”, “*”, “_”, “+”, “=”, “?”, “/”, “~”, “;”, “:”, “,”, “<”, “>”, “\”, “)”, “.”
$words = Import-Csv “\\path to word list\words.csv”
$max = $words.Count

$first = New-Object system.Random
$1value = $first.next(0, $max)
$firstword = $words[$1value].word
$firstword = $firstword.toupper()

Start-Sleep -milliseconds 20
$second = New-Object system.Random
$2value = $second.next(1, 23)
$special = $symbols[$2value]

Start-Sleep -milliseconds 300
$third = New-Object system.Random
$3value = $third.next(0, $max)
$secondword = $words[$3value].word

Start-Sleep -milliseconds 230
$num = New-Object system.Random
$4value = $num.next(0, $max)
$4value = $words[$4value].number

$newpass = “$firstword$special$secondword$4value”

Echo “`n”
$newpass
Echo “`n”

So as you can see I am using the word list to pull the two words as well as the number value. In order to get my capital I am using the toupper() function on the first word, and for the special character I create an array of characters and then pick one to use.

Any comments or questions please let me know.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: