A fellow at work wanted a script to generate strong passwords from a dictionary file. The "l337" hashtable in the first line is the list of characters that we'll be replacing. The $skip variable adds a little variance so we won't (likely) generate the same password twice given the same word.
$leet = @{e=3;o=0;l=1;a=4;i='!';t=7}$rand = new-object System.Random$words = import-csv dict.csv$word = ($words[$rand.Next(0,$words.Count)]).Wordif ($args[0]) { $word = $args[0] }$leet.Keys | foreach-object { $skip = $rand.Next(0,3); if ($skip -ne 0){ $word = $word.Replace($_,$leet[$_]) } }$word
Here's the dictionary I used: File Attachment: dict.csv (6 KB)
> ./generate-password.ps11ass!7ude!nterd!ctc4j013par!ahruff!4nr3cantpl3th0r4> ./generate-password.ps1 "quixotic"qu!x07!cquixo7icquix0tic
UPDATE: Jeff opines (correctly) passphrases are where it's at, so...
$rand = new-object System.Random$conjunction = "the","my","we","our","and","but","+"$words = import-csv dict.csv$word1 = ($words[$rand.Next(0,$words.Count)]).Word$con = ($conjunction[$rand.Next(0,$conjunction.Count)])$word2 = ($words[$rand.Next(0,$words.Count)]).Wordreturn $word1 + " " + $con + " " + $word2
Yielding:
> ./generate-passphrase.ps1'foible my finessebolster but permeateaugury my dogmaticsurfeit the mercurialreconcile but dexterityacarpous our inveighperilous and bequestcognizant we foiblecalipers and vilifytrickle our enzymevigorous we ominousascertain + dubioussuborn but middling
I totally agree that passphrases are better. I've advocated them to family and friends and have a few long-ass passphrases myselfs
Ads by The Lounge