Friday, February 20, 2026

Re: single user machine, one "user" now(?) has no password (I didn't do it). [edited for clarity]

sha256 hash (file ends with newline):
SHA256 (pwgenerator) = 740470dc3ea3911a19c7165d3439136ff8fb180a7f65ad31c6086a91957b77e4

contents:
#!/bin/ksh

set -e
trap 'error=$?; if (($error)); then print -ru2 -- "$0: line $LINENO: $error"; fi' ERR

if [ -t 1 ]; then
        tput clear || exit 1
        tput cup 0 0 || exit 1
        tput el || exit 1
fi

LENGTH=20
VARIATION=4
set -A P
set -A Q
while :; do
        for i in $(dd if=/dev/random bs=4 count=1 2>/dev/null |
          hexdump -e '/1 "%u\n"')
        do
                ((i<190)) && P[${#P[@]}]="$(
                        printf '%b' "\\$(printf %o "$((i%95+32))")"
                )"
        done
        l=${#P[@]}
        if ((l >= LENGTH)); then
                nu=$(printf '%s\n' "${P[@]}" | grep -c '[[:upper:]]' || true)
                nl=$(printf '%s\n' "${P[@]}" | grep -c '[[:lower:]]' || true)
                nd=$(printf '%s\n' "${P[@]}" | grep -c '[[:digit:]]' || true)
                nx=$(printf '%s\n' "${P[@]}" | grep -c '[ [:punct:]]' || true)
                ((nu*nl*nd*nx)) || continue
                until ((l-LENGTH <= VARIATION)); do
                        # sum of chars. - types of chars. >= ...
                        ((l-4 >= l-LENGTH-VARIATION)) || continue 2
                        ((nu>1)) && rmc="$rmc[:upper:]"
                        ((nl>1)) && rmc="$rmc[:lower:]"
                        ((nd>1)) && rmc="$rmc[:digit:]"
                        ((nu>1)) && rmc="$rmc [:punct:]"
                        rmc="[$rmc]";  unset Q
                        for i in ""; do
                                if [ -z "$rmc" ] ||
                                  ! print -r -- "$i" | grep -q "$rmc"; then
                                        Q[${#Q[@]}]="$i"
                                else
                                        rmc=
                                fi
                        done
                        set -A P -- "${Q[@]}";   l=${#P[@]}
                        nu=$(printf '%s\n' "${P[@]}" | grep -c '[[:upper:]]' || true)
                        nl=$(printf '%s\n' "${P[@]}" | grep -c '[[:lower:]]' || true)
                        nd=$(printf '%s\n' "${P[@]}" | grep -c '[[:digit:]]' || true)
                        nx=$(printf '%s\n' "${P[@]}" | grep -c '[ [:punct:]]' || true)
                done
                break
        fi
done

if [ -t 1 ]; then
        jot -nb . -s '' $l; print $l
        read -r unused?"$(printf '%s' "${P[@]}")"
        tput cup 0 0; tput el
        tput cup 1 0; tput el
else
        printf '%s' "${P[@]}";  print
fi

No comments:

Post a Comment