News for hackers. Stuff that matters.
Re:Tweetable Python – Tweetable Python 3.7 Documentation by chriswitts on Wednesday August 08, 2018 @02:22AM (#17713588)
I have a little function for generating some random characters

    ######################################
    # Generate a random password from /dev/urandom
    # pw [length [num_passwords [characters]]
    # Arguments:
    #   $1 => The length of password
    #   $2 => The number of passwords to generate
    #   $3 => The acceptable character set, PCRE regex
    ######################################
    function pw {
        if [[ "x$1" == "x-h" ]]; then
            echo "Usage: pw [length:20 [num_passwords:1 [character_set:a-zA-Z0-9._!@#$%^&*()]]]"
        else
            LC_CTYPE=C \
                tr -dc "${3:-'a-zA-Z0-9._!@#$%^&*()'}" < /dev/urandom \
                | fold -w "${1:-20}" \
                | head -n "${2:-1}"
        fi
        # There's always `openssl rand -base64 12` for simplicity
    }

There are no comments on this comment yet.