0

Get-Password

I’ve been really looking at enhancing some of my own personal security models as of late and for accounts that i have for internal only but typically can only be accessed with a web interface so I couldn’t make use of exported credential Passwords as I would prefer to.

So to get round this issue I built this nice little function, which takes a String input from you and a type definition Integer to determine whether you are passing the plaintext version and wanting the Hashed version of the Password returning or whether you want to get the plaintext version of a previously hashed password.

function Get-Password

{

   param (

    [Parameter(Mandatory=$true,HelpMessage=“Please Provide Password.”)][String]$Password,

    [Parameter(Mandatory=$true,HelpMessage=“1 = hashed 2 = unhashed.”)][INT]$Type

    )

    If ($Type -eq “2”)

        {

        $pwd = [System.Text.Encoding]::UTF8.GetBytes($Password)

        $Global:Hpwd = [system.convert]::ToBase64String($pwd)

        Write-Host Your Hashed password is $hpwd

        }

         else

        {

        $global:uhpwd = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Password))

        Write-Host Your unhashed password is $uhpwd

        }

}

What this will do is turn your normal phrase into as base64 encoded string – Although this only really adds a small further layer of security it could be used to simplify your password management – think of this as a level of Security by Obscurity

I know that it has simplified mine considerably.

So as an example to this Function you would run it as below specifying that the type is 2 as this will convert the password into a base64 encoded string

Get-Password -Password NaffPassword -Type 2

And it would output the following

Your hashed password is TmFmZlBhc3N3b3Jk

You can then also see that this stores this in a Global Variable which we can see is defined as $Hpwd

So as this is stored in a Variable this can then be fed either to the same function again or can be used within other script areas.

So for example you could then run the function as following using the type as 1 to return the unhashed Password

Get-Password -Password $Hpwd -Type 1

And the result would be

Your unhashed password is NaffPassword

Hopefully you may find this little Function useful or even have some suggestions on how this could be improved further.

The ability to add in the Scripts is thanks to this Brilliant PowerShell ISE Addon CopyToHtml created by Gary LaPointe which you can find at http://blog.falchionconsulting.com/index.php/2012/10/windows-powershell-v3-ise-copy-as-html-add-on/

 

Leave a Reply