Mumia W. wrote:
On 09/29/2006 01:44 PM, Rob Dixon wrote:
Derek B. Smith wrote:
--- "Mumia W." <[EMAIL PROTECTED]>
wrote:
What is the purpose of this program?
To generate a random 6 character string.
If the first character starts with a # then I just
ignore the new string and tell it to goto LABLE, b/c
for 0-32 on the ASCII table cannot be used as a 1st
character in a user password.
## generate random 8 char password.
PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $password = join '', map { $a[int rand @a] } 0 ..
5;
#if first char is a-z then print it else warn
#chop string into individual characters
my @chars = unpack ("A1" x length($password),
$password);
if ($chars[0] =~ /^\D/) {
print "Your new password is:\t",@chars,"\n";
}
else {
#print "string starts with number:\t",@chars,
"\trestarting\n";
#substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e);
## execute with regexp substitute ?/? goto PASSWD;
}
This will do what you want. It shuffles all of the possible characters
and joins
them into a string, and then finds the first substring of six
characters that
starts with a non-numeric character. The only proviso is that a
password can
never have the same character twice, which isn't true of the general
solution.
use List::Util qw/shuffle/;
my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z');
my ($password) = $a =~ /(\D.....)/;
HTH,
Rob
Aren't you concerned that this is random in a completely wrong way? Only
one of each character can appear in the password, and that's kind of weak.
No. I mentioned it in my post, but since it's meant for password generation and
not for creating data that's 'random' in the mathematical sense I think it's
plenty good enough. Even if you take truly random samples of six characters out
of a 62-character set, about three-quarters of them will be six distinct
characters.
It's also a /very/ minor issue that you assign to $chars but then use $a
after; the main problem is that this password generating algorithm is
that it is, to steal a phrase from Lo Wang, "weaker than a baby's
[passing gas]."
I fixed that in a later post. I wrote a working version and then posted an
earlier incarnation. Call me an old [passing gas] if you will. :(
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>