PoshCode Archive  Artifact [781a5ba891]

Artifact 781a5ba8916b6693c719a944f6c41afefd6b0f9564e1d812734f108df65cde85:

  • File Password-manager.ps1 — part of check-in [cce17ff7c0] at 2018-06-10 13:59:28 on branch trunk — Got bored, decided to create this. (user: x0wllaar size: 2300)

# encoding: utf-8
# api: powershell
# title: "Password manager"
# description: Got bored, decided to create this.
# version: 0.1
# author: x0wllaar
# license: CC0
# x-poshcode-id: 5696
# x-archived: 2015-01-31T20:30:43
# x-published: 2015-01-19T14:17:00
#
# It will generate passwords anew every time you run it, based on the website name, account name, length, and the password number
# Run it as ./Manager.ps1 pass.csv
# Structure of the .csv
# Header: SiteName,AccName,Len,PassNum
# Then the values themselves
# The fields are:
# 1)SiteName – name of the website
# 2)AccName – account name
# 3)Len – length of the password (max 64)
# 4)Password number – the number of a password (intened to be increased in order to generate a new password for the same website/account)
# Example .csv:
# SiteName,AccName,Len,PassNum
# test.com,test,10,1
# test2.com,test,10,2
#
$alphabet = '!"¹;%:?*()_+=-~/\<>,.[]{}1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';$iter=343
[Console]::Write("Enter your master password: ")
$pass="";while($true){$key=[Console]::ReadKey($true);if($key.Key-eq[ConsoleKey]::Backspace){[Console]::Write("`b `b");$pass = $pass.Substring(0, ($pass.Length - 1))}elseif($key.Key-eq[ConsoleKey]::Enter){break}else{$pass+=$key.KeyChar;[Console]::Write("*")}};""
$htool=New-Object System.Security.Cryptography.SHA512Managed
$hpass=$htool.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($pass))
$creds=@()
(Import-Csv $args[0])|%{
    $hsite = $htool.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($_.SiteName)); $hname = $htool.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($_.AccName))
    $interw=@(); (0..63)|%{$interw+=$hsite[$_];$interw+=$hpass[$_];$interw+=$hname[$_];}
    $seed=$htool.ComputeHash($interw)
    (0..($iter+$_.PassNum-1))|%{$seed=$htool.ComputeHash($seed)}
    $spass="";(0..($_.Len-1))|%{$spass += $alphabet[($seed[$_] % $alphabet.Length)]}
    $cred = New-Object -TypeName PSObject; 
    Add-Member -InputObject $cred -MemberType NoteProperty -Name SiteName -Value $_.SiteName; 
    Add-Member -InputObject $cred -MemberType NoteProperty -Name AccName -Value $_.AccName; 
    Add-Member -InputObject $cred -MemberType NoteProperty -Name Pass -Value $spass
    $creds += $cred
}
$creds