![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
Re: Efficient way to verify scalar contents (updated x3)by haukex (Bishop) |
on Jun 22, 2020 at 07:05 UTC ( #11118347=note: print w/replies, xml ) | Need Help?? |
See also How to ask better questions using Test::More and sample data. You can do it all in a single regex, see perlretut (and perlre) in regards to alternations, character classes, and lookaheads. However, perhaps my test cases below will give a hint that these password rules aren't necessarily good indicators of password quality; perhaps use one of the other established methods like Data::Password::zxcvbn instead. If this happens to be for a website, note there's also a JavaScript version of the "zxcvbn" algorithm that allows you to give live feedback to the user when and why a password isn't good, so they can know while choosing one; of course it should still be verified on the server in case they have JS disabled. Update: Note that given/when are unforunately still experimental, in this case I'd suggest normal ifs instead. Update 2: The talk on the library is great: https://youtu.be/vf37jh3dV2I (even just the first five minutes on the issues) Update 3: A slightly optimized version of the regex below, that turns out to be pretty fast:
Original code:
In Section
Seekers of Perl Wisdom
|
|