Search This Blog

Code snippets and memory joggers

Saturday, January 10, 2009

Password Generator

Some code I found out there and didn't want to loose it

#!/usr/bin/perl
# Author Kirk Brown
# http://perl.about.com/od/perltutorials/a/genpassword.htm
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
}

No comments:

About Me

I love to travel and meet new people, motorbikes, moving my body through dance, martial arts and yoga. I'm a lifelong learner interested in how things work, and the way people think and make their decisions. My choice of superpower would be to speak with someone and understand them completely, including their intention and for me to be able to communicate my intention to them clearly in their own language. As an Amazon Associate, I may earn from links to qualifying purchases.