Gossamer Forum
Home : General : Perl Programming :

Random Password Subroutine.

Quote Reply
Random Password Subroutine.
What's the problem with this subroutine. This routine provides a random password, its working fine in another script, but giving me an error with a new script. Any ideas?

Error: Missing right curly bracker or square bracket at line no. 7.

I am unable to find that missing curly bracket. Any help would be appreciated.

------------------------------------------
sub encrypt
{
my($plain) = @_;
my(@salt);
@salt = (
'a'..'z', 'A'..'Z', '0'..'9', '.', '/');
srand(time() ^ ($$ + ($$ << 15)) );
return crypt($plain,$salt[int(rand(@salt))].$salt[int(rand(@salt))]);
}
----------------------------------------


Thanks,

Zeshan.
Quote Reply
Re: [zeshan] Random Password Subroutine. In reply to
That routine looks fine. your missing curley brace is somewhere else
Quote Reply
Re: [Mark Badolato] Random Password Subroutine. In reply to
What about the below given?...Still giving error.

Thanks for your input.

-------------------------------------------------

#!/usr/bin/perl


use strict;
use warnings;

$pass =
"test";

$en_pass = &encrypt($pass);

print
"$en_pass";

sub encrypt
{
my($plain) = @_;
my(@salt);
@salt = (
'a'..'z', 'A'..'Z', '0'..'9', '.', '/');
srand(time() ^ ($$ + ($$ << 15)) );
return crypt($plain,$salt[int(rand(@salt))].$salt[int(rand(@salt))]);
}
-----------------------------------------
Quote Reply
Re: [zeshan] Random Password Subroutine. In reply to
This works for me:

use strict;
use warnings;

my $pass = "test";

my $en_pass = &encrypt($pass);

print "$en_pass";

sub encrypt
{
my($plain) = @_;
my(@salt);
@salt = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/');
srand(time() ^ ($$ + ($$ << 15)) );
return crypt($plain,$salt[int(rand(@salt))].$salt[int(rand(@salt))]);
}

Hope that Hels.