Hi, my name is Lage Berger Jensen. I am currently working as a Senior Engineer at Sopra Steria in Oslo, Norway. I am a technology and automation enthusiast with 11 years of experience from various aspects of IT. At the moment I am very passionate about all things Powershell and C#.

7 November 2019

Passphraser: A Powershell passphrase generator + an excuse to look closer at Plaster

by Lage Berger Jensen

I try to keep passwords unique for every login I create, both my personal ones and the ones I create for my employer. My imagination only goes so far though and I end up wasting precious time coming up with new passphrases. I have been using builtin generators in KeePass and Bitwarden, but I figured I needed one for my console as well. So I created the Passphraser module for Powershell.

I have been using this project as an opportunity to take a closer look at other things too. I have been wanting to create my first real Plaster template, take a closer look at build files, unit tests, how to generate module help files, creating online docs and checking what Appveyor is all about. This is also the first module I have published to the Powershell Gallery, hopefully it will not be my last. At the time of writing it has been published for 19 hours and it has been downloaded 2 times. Woohoo!

The Passphraser module is built on my newly created ‘Plastered’ Plaster template (even though it’s overkill for such a small module, but hey, why not?)

I created a GitHub repo for my Plaster templates where ‘Plastered’ is published if you want to take a closer look at it. The template includes Powershell module files, appveyor.yml for Appveyor, mkdocs.yml for Readthedocs, .gitignore, LICENSE and README.md for GitHub, test files for Pester, build files for psake and docs for Readthedocs content. Check out my PlasterTemplates GitHub repo.

Passphraser is a small and simple module with only one function; New-Passphrase, which returns a random passphrase as a System.String. It contains 3065 english words. For easy access pipe the output to ‘clip’. By default New-Passphrase returns 3 words with space/whitespace as a separator. You can of course pass parameters to increase the complexity of the passphrase. New-Passphrase can include a specified amount of numbers and special characters if you want. It can also include an uppercase word, but none of the parameters are required.

The syntax of New-Passphrase is:

New-Passphrase [[ -AmountOfWords ] < Int32 > ] [[ -Separator ] < String > ] [ -IncludeNumbers ] [[ -AmountOfNumbers ] < Int32 > ] [ -IncludeUppercase ] [ -IncludeSpecials ] [[ -AmountOfSpecials ] < Int32 > ] [ -AsObject ] [ -WhatIf ] [ -Confirm ] [ < CommonParameters > ]

Let’s try it out:

PS C:\ > New-Passphrase giant throat aboard

By running the command without any parameters it returns a 3-word passphrase without any numbers or special characters and no uppercase word. In this case it returned ‘giant throat aboard’.

PS C:\ > New-Passphrase -IncludeNumbers jealous impart 9carriage

By passing switch ‘-IncludeNumbers’ it returns the default 3 words, but it also adds a number, the default amount of numbers is 1.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 4 valuable magical1 1tender

By passing switch ‘-AmountOfNumbers’ I can specify how many numbers I want in my passphrase. Here it returns the default 3 words and adds 3 numbers.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 -AmountOfWords 5 zoom 0laugh water 3fearless5 roof

I can increase the amount of words by passing switch ‘-AmountOfWords’. Here it returns 5 words and 3 numbers.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 -AmountOfWords 5 -Separator '-' chide-marry-39abortive-5resonant-toothpaste

I can change the separator by using ‘-Separator’. Here it returns 5 words and 3 numbers with “-“(dash) as separator.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 -AmountOfWords 5 -Separator '-' -IncludeSpecials face-incandescent-scam:-pocket-pot613

If I want to include any special characters I pass switch ‘-IncludeSpecials’. Here it returns 5 words and 3 numbers with “-“(dash) as separator and 1 special character. Amount of special characters defaults to 1.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 -AmountOfWords 5 -Separator '-' -IncludeSpecials -AmountOfSpecials 5 boy < - : 894use- + cattle-panoramic { * -write

If I want to include 5 special characters I pass parameter ‘-AmountOfSpecials’. Here it returns 5 words and 3 numbers with “-“(dash) as separator and 5 special character.

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 3 -AmountOfWords 5 -Separator '-' -IncludeSpecials -AmountOfSpecials 5 -IncludeUppercase evasive * -precious5 .| - {) 1 COMBATIVE-7obsolete-waylay

If I want to include an uppercase word I pass parameter switch ‘-IncludeUppercase’. Here it returns 5 words and 3 numbers with “-“(dash) as separator and 5 special character and an uppercase word.

As you can see, you can generate both simple and very complex passphrases with this if you want.

Let’s try one last one for fun:

PS C:\ > New-Passphrase -IncludeNumbers -AmountOfNumbers 128 -AmountOfWords 256 -Separator '-' -IncludeSpecials -AmountOfSpecials 64 -IncludeUppercase parallel-8sheep.-scat ; /-promise- + internal-guide-celebrate-1attack-insult-disap22pear- < print-:climb-6awake-ingest4-indulge-question-glib-subscribe- } 6 want7-bashful3-glow-15crowd-inhabit-progress\-sisters-spin6-war7-15crowd-penitent0-6undesirable-3ocean-caring1-gate-76inaugurate2-insure-suck @ -nest-terminate-whole-scissors-9alarm-behold-rhythm : -connection-shade-9solve-1expert6 - + bread > -imaginary-1girls-1jump-naughty0-intelligent-5hope-burst-jumbled-7private6-threatening - @ arrogant-2shear1- | opt0imal-gentle-1dye9-save-little7-tender-click-cash-sap22-twist-itchy.-9insidious-3333ADDITION-cent-morning-realize-battle-premium7-pat-nail7-inflate-crazy- < numberless-restrain8 #-body-<leap-ancient-evasive-^=grotesque-hesit%ant8^-functional.-redundant3-patch-=tasteless9-toe2-pink-{7treat-.7flower-"ratty-4grandmother-4repair9-!8sloppy-dazzle-2lift-plastic-=incredible-|opt0-dashing9-%@callous-throw-craven7-sophisticated-compel5-8vacation-bird9-1magenta9-*dinosaurs^-!tranquil3-supreme135-exchange0-nauseating-rude9-3force-grow5-wax-board-beseech-route-2bells-rings27>-ghost9-didactic-friction-63follow-9saddle\-disuse-reaction&-deranged3-(6authority:-/trade-complete-unarmed!-beds0-9gainsay-saunter-rule-bereave-racial-6slim-ply-5sweat-6wave-quizzical"-sparkling-mailbox4-7muddled$-wooden-input-music-sturdy-\pain\t4-\pain\-derive-nippy-guiltless-0ticket07-install4-contemn-tired3-separate-cold-toss-rid-7billowy-trouble-<grieving4-output(-strange-romantic-short-slippery-paste-aspiring4-wild-succeed-carpenter-stoop-2snail7s-condemned=-minister3-prevent+,-feigned0-56male-rest-orange-laborer-polish9-half-honey.,-dusty-safe-swing-shame5-?infringe-sit%-{3glue-fixed-shiver8-fulfil-faucet-scarp-;7misuse-5obstruct-aboriginal-basin9-^discreet-1bewildered-salve-sever7-efficient-sugar*&+-hush-like/-slip-0view-advertisement-silent8-beautiful-testy43-statuesque1<-share)-overrated-vex-sore9-event+,-slave-near-mere-@satisfying3-laugh1-2disastrous-5family-4boundary-distinct3-horse7-third-needy-acoustics-careless-subtract-35abiding-cub-4diminish-jellyfish-8contribute-,3quickest0

I took the opportunity to take a closer look at classes in Powershell and created a new Passphrase class for this module. The module has been rewritten to use the Passphrase type. It is now possible to pass parameters switch -AsObject to return a Passphrase object that can be used for further processing.

I can e.g.:

PS C:\ > $Passphrase = New-Passphrase -IncludeNumbers -Separator '-' -IncludeSpecials -AsObject PS C:\ > $Passphrase Words : { fantastic , admire , tiny } Numbers : { 3 } Specials : { ? } Separator : -

I now have a passphrase object with 3 words; ‘fantastic’, ‘admire’ and ‘tiny’, one number; ‘3’, one special character; ‘?’, and ‘-‘ (dash) as separator. The Passphrase class contains these methods:

PS C:\ > $Passphrase | Get-Member -MemberType Method TypeName: Passphrase Name MemberType Definition ---- ---------- ---------- AddNumber Method void AddNumber ( int AmountOfNumbers ) AddSpecial Method void AddSpecial ( int AmountOfSpecials ) AddUppercase Method void AddUppercase () AddWord Method void AddWord ( string [] Words ) Equals Method bool Equals ( System.Object obj ) GetHashCode Method int GetHashCode () GetType Method type GetType () ToString Method string ToString ()

Ok, let’s try the AddWord method, this method wants input as a string array, so I’ll pass two strings in an array:

PS C:\ > $Passphrase . AddWord (@( 'beer' , 'pizza' ))

If I check the Words property of my object now, I should have 5 words:

PS C:\ > $Passphrase . Words fantastic admire tiny beer pizza

Next, let’s try the AddUppercase method, this method does not need any input, and check the Words property:

PS C:\ > $Passphrase . AddUppercase () PS C:\ > $Passphrase . Words fantastic admire tiny BEER pizza

Both AddNumber and AddSpecial properties accepts input as integer and just wants to know how many numbers and special characters you want, not which numbers and characters. The methods will automatically pick numbers and special characters for you. Let’s try them and check our object:

PS C:\ > $Passphrase . AddNumber ( 1 ) PS C:\ > $Passphrase . AddSpecial ( 2 ) PS C:\ > $Passphrase Words : { fantastic , admire , tiny , BEER … } Numbers : { 3 , 2 } Specials : { ? , & , ,} Separator : -

Now you can see that the AddNumber method added the number ‘2’ and the AddSpecial method added ‘&’ and ‘,’ to our object. To return the passphrase as a string use the ToString method:

PS C:\ > $Passphrase . ToString () fantastic , -admire - & 3tiny-BEER-3pizza ?

Check out the Passphraser docs for more info. File all bugs/feature requests at Passphraser GitHub repo.

tags: powershell - passphrase - passphraser - password

Posts