Gossamer Forum
Quote Reply
regex
  unless ((length($in{'password'}) >= 4) and (length($in{'password'}) <= 12) and ($in{'PASSWORD'} =~ /^([a-zA-Z]{2,}[0-9]{2,})+$/))



Can somone see what is wrong with the above code. The regex is not working correctly. It should require a minimum of two letters and two numbers be in 'password'.
Quote Reply
Re: [thedosmann] regex In reply to
it's requiring the format to be \w\w+\d\d+. in other words, you can't have \w\d\w\d.

--Philip
Links 2.0 moderator
Quote Reply
Re: [King Junko II] regex In reply to
Thanks for your reply. I have tried a number of combinations.

Any suggestions???
Quote Reply
Re: [thedosmann] regex In reply to
Hi,

The regex is ok. Take a look at $in{PASSWORD}

it should be $in{password}?

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] regex In reply to
The regexp is valid, yes... but it doesn't do what he thought it would. Try the following code:
Code:
$string = "a1b2";
$length = length $string;
$num++ while ($string =~ /\d/g);
$let++ while ($string =~ /[a-zA-Z]/g);
if ($length >= 4 && $length <= 12 && $num >= 2 && $let >= 2) {
print "okay";
}

--Philip
Links 2.0 moderator
Quote Reply
Re: [King Junko II] regex In reply to
You also need a check for the rest of the characters. I assume the code is from DBMAn so if I enter my password as:

trash:1:2

....then I just screwed the database :)

Last edited by:

Paul: Mar 29, 2002, 1:52 AM
Quote Reply
Re: [King Junko II] regex In reply to
OK, this is what I ended up with and that is working ..THANKS



Smile

$string = $in{'password'};
$length = length $string;
$num++ while ($string =~ /\d/g);
$let++ while ($string =~ /[a-zA-Z]/g);


unless ((length($in{'password'}) >= 4) && (length($in{'password'}) <= 12) && ($num >= 2 && $let >= 2) && ($in{'password'} =~/^[^:]+$/)) {
$message = "Invalid password: '$in{'password'}'. Must be 4 to 12 characters and contain at least two numbers and two letters.";
last CASE;
Quote Reply
Re: [thedosmann] regex In reply to
You'd probably be best removing the while loops and using something like:

Code:
my ($pw, $error) = ($in{password}, 0);
my ($c1) = ($pw =~ tr/[0-9]//);
my ($c2) = ($pw =~ tr/[a-zA-Z]//);

unless (length $pw > 3 && length $pw < 13 && index($pw, ':') == -1 && $c1 > 2 && $c2 > 2)
{
$message .= "Invalid password!";
last CASE;
}

Last edited by:

Paul: Mar 29, 2002, 9:52 AM
Quote Reply
Re: [Paul] regex In reply to
Thanks....

I taped it over my other code and got an initial wrong result but then changed the > to >= to the qualifier vars. WORKS GREAT..Thanks
Quote Reply
Re: [thedosmann] regex In reply to
Whoops, yeah my mistake. You mean for $c1 and $c2 ?

I edited it about 20 times and still got it wrong...hehe

Last edited by:

Paul: Mar 29, 2002, 11:42 AM
Quote Reply
Re: [Paul] regex In reply to
How about if I want the password to be:

1. mixed of only English letters and numbers (at least 1 letter and 1 number and no any other character)

2. The first character must be a letter.

3. length $password >= 6 && length $password >= 12

Any help is greatly appreciated.
Quote Reply
Re: [thedosmann] regex In reply to
I found the answer to my question:

$pass =~ /^(?=.*\d)[A-Za-z][A-Za-z0-9]{5,11}$/
Quote Reply
Re: [Fortune] regex In reply to
That regex doesn't match your original specifications.
Quote Reply
Re: [thedosmann] regex In reply to
Hello Paul,

It does match my specifications:

Begin with a letter, at least 1 number, only letters and numbers, 6-12 characters.

Why do you think it doesn't?
Quote Reply
Re: [Fortune] regex In reply to
>>
Why do you think it doesn't?
<<

For starters you have 5,11 not 6,12 :)
Quote Reply
Re: [thedosmann] regex In reply to
Hello Paul,

[A-Za-z] get 1 letter character, plus

[A-Za-z0-9]{5,11}

It's total {6,12}