Skip to content

Instantly share code, notes, and snippets.

@timjb
Created June 10, 2018 12:42
Show Gist options
  • Save timjb/0620baf26d1fb72119661549ba2b8cae to your computer and use it in GitHub Desktop.
Save timjb/0620baf26d1fb72119661549ba2b8cae to your computer and use it in GitHub Desktop.
YPassword LastPass CSV Export
#!/usr/bin/env zsh
print -- "usage: $0:t"
print -- " generate a password using the ypassword method"
print -- " See http://ypassword.espozito.com for more informations"
passfile="$HOME/.passwd"
echo -n "Enter your master password please: "
oldmodes=$(stty -g)
stty -echo
read password
stty $oldmodes
function col {
colnum=$1
shift
echo $* | awk "{print \$$colnum}"
}
echo ""
echo "url,type,username,password,hostname,extra,name,grouping"
while read line; do
site=$( col 1 $line )
domainName=$( echo $site | sed 's/.*\.\([^.]*\.[^.]*\)$/\1/')
loginName=$( col 2 $line )
longueur=$( col 3 $line )
base64=$( col 4 $line )
hashalgo=$( col 5 $line )
num=$( col 6 $line )
if [[ -x =shasum ]]; then
case $hashalgo in
sha1) hashcmd="shasum -a 1" ;;
sha256) hashcmd="shasum -a 256" ;;
sha512) hashcmd="shasum -a 512" ;;
*) print -- "Unknown algorithm: $hashalgo" >&2
exit 1
esac
else
case $hashalgo in
sha1) hashcmd="sha1sum" ;;
sha256) hashcmd="sha256sum" ;;
sha512) hashcmd="sha512sum" ;;
*) print -- "Unknown algorithm: $hashalgo" >&2
exit 1
esac
fi
if [[ $base64 = "b64" ]]; then
# make a hex2b64
hashcmd="$hashcmd | cut -f1 -d\\ | xxd -r -p | base64"
fi
cmd='echo -n "'$password$num$domainName'" | '$hashcmd' | awk "{print substr(\$1,1,'$longueur');}"'
sitePasswd="$(eval $cmd)"
echo "https://$site/,,$loginName,$sitePasswd,,,$site,"
done < $passfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment