On Dec 20, Batchelor, Scott said:

>1.     I am trying to not allow doubled numbers or symbols(e.g. 99 or %%)

To ensure a character is not immediately repeated, do

  !/([^A-Za-z])\1/

That means "not matching 'a non-alpha followed by itself'".

>2.     Also want to make it so the password has at least two numbers or
>symbols in the first 8 characters.

This is easily done as

  (substr($passwd, 0, 8) =~ tr/a-zA-Z//c) >= 2

That means "the count of NON-a-zA-Z characters in the first 8
characters of $passwd is at least 2."

>3.     And finally the password must be at least 5 different characters.

This is best done with a hash, really.

  my %chars;
  @chars{split //, $passwd} = ();
  if (keys(%chars) < 4) {
    die "not enough unique characters in $passwd\n";
  }

So putting these three all together...

  if ($passwd =~ /([^a-zA-Z])\1/) {
    die "duplicated character ($1) in $passwd\n";
  }

  if (substr($passwd, 0, 8) =~ tr/a-zA-Z//c < 2) {
    die "not enough non-alphabetics in $passwd\n";
  }

  my %chars;
  @chars{split //, $passwd} = ();
  if (keys(%chars) < 4) {
    die "not enough unique characters in $passwd\n";
  }
  

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to