Bash password creation

I am currently generating a password which is a hash of the date. I would like to increase this generated password protection by adding some uppercase, lowercase, numeric and special characters, up to 10 characters in total.

What I have now is below. As you can see, it is assigning the result to my PASSWORD variable.

PASSWORD=$(date +%s | sha256sum | base64 | head -c 15)

      

I'm not sure if I can do this inline or if I need to create a function in my bash script to satisfy? Is it possible?

Thank you very much in advance.

+3


source to share


1 answer


C tr

and head

:

password=$(tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10)

echo "$password"

      

Output (example):



k? lmyif6aE

tr

reads bytes through stdin from Linux special random device / dev / urandom and removes all bytes / characters but A

before Z

, A

before Z

, 0

before 9

and !?%=

. tr

sends its output via stdout to stdin head

. head

truncates the output after 10 bytes.

+6


source







All Articles