Generate valid Unix username and password in Perl Generate valid Unix username and password in Perl unix unix

Generate valid Unix username and password in Perl


For generating password You can use:

$password = `date | md5sum | fold -w 10 | head -n 1`;$password = crypt($password,'some_string');

It's actually more Bash than Perl but it does the job.


From http://sysadminsjourney.com/content/2009/09/16/random-password-generation-perl-one-liner/

perl -le 'print map { (a..z,A..Z,0..9)[rand 62] } 0..pop' 8

Will generate a random 8 character string from the characters a-z, A-Z and 0-9 .

You should be able to modify this to generate the username and password.

Username would be:

perl -le 'print map { ([a-z_][a-z0-9_][rand 62] } 0..pop' 30

The password would be similar, but you would need to use the passwd command to actually set it to the user. Not sure if Perl has an equivalent.


As mentioned by others , its more BASH than perl. Here is my way of generating the password:

passwd=`date +%s | sha256sum | base64 | head -1 | cut -c 1-8`