Friday, November 17, 2006

Perl : Generating password with a subroutine

A subroutine to generate a password :-) When you find it hard to create one.

sub generatePassword
{
    my $passwd_size = shift;
    my @alphanum = ('a'..'z', 'A'..'Z', 0..9,'!','#','$','%','&','*','@','`');
    my $password = join '', map $alphanum[rand @alphanum], 0..$passwd_size;

    return $password;
}

Usage

&generatePassword(10); ### returns password of 10 chars

1 comment:

Anonymous said...

Amiable brief and this post helped me alot in my college assignement. Say thank you you for your information.