This is a simple script to generate a short, readable password in Perl. Be warned that using a password this short and simple can be a security risk. I would suggest using this Perl password generation script only to create a temporary password, perhaps to set on an account long enough for someone to log in and change it if they've forgotten their current password.
Let's take a look at the password generation script in it's entirety, and then see what we're doing step by step.
#!/usr/local/bin/perl
print generatePassword(10) . "\n";
exit;
sub generatePassword {
$length = shift;
$possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
while (length($password) < $length) {
$password .= substr($possible, (int(rand(length($possible)))), 1);
}
return $password
}
The meat of the password script is contained in the generatePassword function. This function is called with a single number that corresponds to the length of the password you want to generate. I would suggest a minimum of 10, but be careful - because these passwords are so short and readable, they are very vulnerable to brute force attacks.
Password Function Usage
Using the function in your own scripts is very simple. First make sure you copy the entire subroutine into your own script somewhere. Then when you want a password simple call the function with the password character length you want. For example, if you want a 10 character password, you would say: $tempPass = generatePassword(10);
For a 15 character password:
$tempPass = generatePassword(15);
Next: How the Perl password generation function works
