use gpg to generate passwords
This commit is contained in:
parent
02155b72ce
commit
8616243660
|
@ -55,7 +55,6 @@ OPTIONS
|
||||||
|
|
||||||
−c Copy password to clipboard.
|
−c Copy password to clipboard.
|
||||||
−l Length of generated passwords.
|
−l Length of generated passwords.
|
||||||
−n Limit passwords to alphanumeric characters.
|
|
||||||
−q Don't print password to stdout.
|
−q Don't print password to stdout.
|
||||||
-t Print list output as a tree.
|
-t Print list output as a tree.
|
||||||
−h Show usage and exit.
|
−h Show usage and exit.
|
||||||
|
|
40
pash
40
pash
|
@ -7,13 +7,14 @@ pw_add() {
|
||||||
|
|
||||||
case $REPLY in
|
case $REPLY in
|
||||||
[yY])
|
[yY])
|
||||||
[[ $OSTYPE == linux* ]] &&
|
length=${length:=50}
|
||||||
check_entropy
|
password=$("${gpg[0]}" --armor --gen-random 0 "$length")
|
||||||
|
password=${password:0:length}
|
||||||
pw_gen
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*) read -rsp "Enter password: " password ;;
|
*)
|
||||||
|
read -rsp "Enter password: " password
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ $password ]] ||
|
[[ $password ]] ||
|
||||||
|
@ -60,33 +61,6 @@ pw_list() {
|
||||||
printf '└%s\b┘\n' "${nest//\//──┴}"
|
printf '└%s\b┘\n' "${nest//\//──┴}"
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_gen() {
|
|
||||||
[[ -r /dev/urandom ]] ||
|
|
||||||
die "/dev/urandom is not readable."
|
|
||||||
|
|
||||||
mapfile -tn "${length:=50}" rand </dev/urandom
|
|
||||||
|
|
||||||
[[ $plain ]] &&
|
|
||||||
glob='[:alnum:]'
|
|
||||||
|
|
||||||
password=${rand[*]//[^${glob:-[:graph:]}]}
|
|
||||||
password=${password:0:$length}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_entropy() {
|
|
||||||
kernel_path=/proc/sys/kernel/random
|
|
||||||
entropy_cur=$(< "${kernel_path}/entropy_avail")
|
|
||||||
entropy_min=$(< "${kernel_path}/read_wakeup_threshold")
|
|
||||||
|
|
||||||
[[ ${entropy_cur:=0} -lt ${entropy_min:=1} ]] && {
|
|
||||||
printf '%s\n' "warn: Not enough entropy to generate a secure password."
|
|
||||||
yn "warn: Continue anyway?"
|
|
||||||
|
|
||||||
[[ $REPLY != [yY] ]] &&
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yn() {
|
yn() {
|
||||||
read -rn 1 -p "$1 [y/n]: "
|
read -rn 1 -p "$1 [y/n]: "
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
@ -113,7 +87,6 @@ usage: pash [add|del|show|list] [name] [flags]
|
||||||
|
|
||||||
-c Copy password to clipboard.
|
-c Copy password to clipboard.
|
||||||
-l length Length of generated passwords.
|
-l length Length of generated passwords.
|
||||||
-n Limit passwords to alphanumeric characters.
|
|
||||||
-q Don't print password to stdout.
|
-q Don't print password to stdout.
|
||||||
-t Print list output as a tree.
|
-t Print list output as a tree.
|
||||||
-h Print this message.
|
-h Print this message.
|
||||||
|
@ -131,7 +104,6 @@ get_args() {
|
||||||
while getopts ":ncvqtl:" opt; do case $opt in
|
while getopts ":ncvqtl:" opt; do case $opt in
|
||||||
c) clipboard=1 ;;
|
c) clipboard=1 ;;
|
||||||
l) length=${OPTARG//[^0-9]} ;;
|
l) length=${OPTARG//[^0-9]} ;;
|
||||||
n) plain=1 ;;
|
|
||||||
q) quiet=1 ;;
|
q) quiet=1 ;;
|
||||||
t) tree=1 ;;
|
t) tree=1 ;;
|
||||||
v) printf '%s\n' "pash 0.01"; exit ;;
|
v) printf '%s\n' "pash 0.01"; exit ;;
|
||||||
|
|
6
pash.1
6
pash.1
|
@ -7,7 +7,7 @@ pash \- simple pasword manager
|
||||||
.B pash
|
.B pash
|
||||||
[\fBadd|del|show|list\fR]
|
[\fBadd|del|show|list\fR]
|
||||||
[name]
|
[name]
|
||||||
[\fB-cnqthv\fR]
|
[\fB-cqthv\fR]
|
||||||
[\fB-l\fR length]
|
[\fB-l\fR length]
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,10 +48,6 @@ Copy password to clipboard.
|
||||||
Length of generated passwords.
|
Length of generated passwords.
|
||||||
.TP
|
.TP
|
||||||
|
|
||||||
.BR \-n
|
|
||||||
Limit passwords to alphanumeric characters.
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.BR \-q
|
.BR \-q
|
||||||
Don't print password to stdout.
|
Don't print password to stdout.
|
||||||
.TP
|
.TP
|
||||||
|
|
Loading…
Reference in New Issue