http://qs321.pair.com?node_id=11118354

in reply to Efficient way to verify scalar contents

```my @RE = (qr/[[:lower:]]/, qr/[[:upper:]]/, qr/[0-9]/, qr/[^[:alnum:]]
+/);
sub check {
local (\$_) = @_;
my \$length = length;
return if \$length < 8;
return if \$length < 12 && (! /\$RE[0]/ || ! /\$RE[1]/ || ! /\$RE[2]/
+|| ! /\$RE[3]/);
return if \$length < 16 && (! /\$RE[0]/ || ! /\$RE[1]/ || ! /\$RE[2]/)
+;
return if \$length < 20 && (! /\$RE[0]/ || ! /\$RE[1]/);
return 1
}

Tested against the tests from Re: Efficient way to verify scalar contents (updated x3) (haukex++).

Update: Or, if you want to abstract away the repeating \$RE[...]

```use List::Util qw{ any };

my @RE = (qr/[[:lower:]]/, qr/[[:upper:]]/, qr/[0-9]/, qr/[^[:alnum:]]
+/);
sub check {
return if \$length < 8;
return if \$length < 12 && any { \$password !~ \$RE[\$_] } 0 .. 3;
return if \$length < 16 && any { \$password !~ \$RE[\$_] } 0 .. 2;
return if \$length < 20 && any { \$password !~ \$RE[\$_] } 0 .. 1;
return 1
}

map{substr\$_->[0],\$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Efficient way to verify scalar contents
by LanX (Cardinal) on Jun 22, 2020 at 12:12 UTC
Please correct me, but do these character classes not depend on localisation?

[[:lower:]] [[:upper:]]

I think passwords should rather be defined in terms of ASCII

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

I'm not sure. I remember [a-z] depending on locale, but it was probably in bash rather than Perl...
```\$ (LC_ALL=en_US.UTF-8; [[ é =~ [a-z] ]] || echo no)
\$ (LC_ALL=C; [[ é =~ [a-z] ]] || echo no)
no
\$ perl -Mutf8 -wE 'say "é" =~ /[[:lower:]]/'
1
\$ perl -Mutf8 -wE 'say "é" =~ /[a-z]/'

\$