tcf22 has asked for the wisdom of the Perl Monks concerning the following question:

I have a pretty straight forward question. Is there a way to verify that a password has at least 1 number, 1 letter, and 1 special character in one regex.

I did it like this, but I would rather not use 3 regexes
if(($new_password !~ /\d/) || ($new_password !~ /[a-zA-Z]/) || ($new_password !~ /\W/)) { return (0, 'Your password must contain at least 1 letter, 1 nu +mber, and 1 special character'); }

Replies are listed 'Best First'.
Re: Regex Password validation
by dws (Chancellor) on May 29, 2003 at 22:09 UTC
    Is there a way to verify that a password has at least 1 number, 1 letter, and 1 special character in one regex.

    This thread discusses a nearly identical question, and the more general problem of how to structure your code to deal with inevitable changes in password requirements.

      Thanks. That sent me in the right direction.

      I'm probably going to leave the code the way it is, to keep it more maintainable, but I couldn't think of how to do it in one regex. So if there is something I can't figure out, I just gotta try.
Re: Regex Password validation
by phydeauxarff (Priest) on May 29, 2003 at 23:12 UTC
    Rather than re-invent the wheel, we use Crypt::Cracklib to keep our users in check.

    Check it out, it might save you some effort.