Skip to content

Commit

Permalink
Improve entropy in password generation by reducing read size
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmid committed Oct 27, 2024
1 parent 04e1338 commit 2c14851
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pw
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pw::gen() {
local password="" class="${2:-"${PW_GEN_CLASS}"}"
while (( "${#password}" != length )); do
# alpine tr does not support [:graph:], use sed instead
password+=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | LC_CTYPE=C LC_ALL=C tr -d '\0[:space:]' | LC_CTYPE=C LC_ALL=C sed "s/[^${class}]//g" | head -c $(( length - ${#password} )) || true)
password+=$(dd if=/dev/urandom bs=$(( length / 64 + 1 )) count=1 2>/dev/null | LC_CTYPE=C LC_ALL=C tr -d '\0[:space:]' | LC_CTYPE=C LC_ALL=C sed "s/[^${class}]//g" | head -c $(( length - ${#password} )))
done
pw::output "${password}"
}
Expand Down

0 comments on commit 2c14851

Please sign in to comment.