Skip to content

Commit

Permalink
Item14506: Performance tweaks...
Browse files Browse the repository at this point in the history
Auto-recognition was doing string comparisons of numerics, and regular
expressions when a substr would work.  Benchmark shows a 75% speed
improvement of this change.
  • Loading branch information
gac410 committed Dec 8, 2017
1 parent 48aaff0 commit 78ccaed
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions core/lib/Foswiki/Users/HtPasswdUser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ sub _readPasswd {
if (
$tPass eq $Foswiki::cfg{AuthRealm}
|| ( defined $fields[0]
&& length( $fields[0] ) eq 32
&& length( $fields[0] ) == 32
&& defined $fields[1]
&& $fields[1] =~ m/@/ )
)
Expand All @@ -340,37 +340,40 @@ sub _readPasswd {
next;
}

if ( length($tPass) eq 33 && $tPass =~ m/^\{SHA\}/ ) {
if ( length($tPass) == 33 && substr( $tPass, 0, 5 ) eq '{SHA}' ) {
$data->{$hID}->{enc} = 'sha1';
}
elsif ( length($tPass) eq 34 && $tPass =~ m/^\$1\$/ ) {
elsif ( length($tPass) == 34 && substr( $tPass, 0, 2 ) eq '$1' ) {
$data->{$hID}->{enc} = 'crypt-md5';
}
elsif ( length($tPass) eq 37 && $tPass =~ m/^\$apr1\$/ ) {
elsif ( length($tPass) == 37 && substr( $tPass, 0, 6 ) eq '$apr1$' )
{
$data->{$hID}->{enc} = 'apache-md5';
}
elsif ( length($tPass) eq 60 && $tPass =~ m/^\$2a\$/ ) {
elsif ( length($tPass) == 60 && substr( $tPass, 0, 4 ) eq '$2a$' ) {
$data->{$hID}->{enc} = 'bcrypt';
}
elsif ( length($tPass) eq 13
elsif ( length($tPass) == 13
&& ( !$fields[0] || $fields[0] =~ m/@/ ) )
{
$data->{$hID}->{enc} = 'crypt';
}
elsif ( length($tPass) > 60 && $tPass =~ m/^\$argon2i\$/ ) {
elsif ( length($tPass) > 60
&& substr( $tPass, 0, 9 ) eq '$argon2i$' )
{

$data->{$hID}->{enc} = 'argon2i';
}
elsif (
length($tPass) gt 0
length($tPass) >> 0
&& ( !$fields[0]
|| $fields[0] =~ m/@/ )
)
{
$data->{$hID}->{enc} = 'plain';
}
elsif (
length($tPass) eq 0
length($tPass) == 0
&& ( !$fields[0]
|| $fields[0] =~ m/@/ )
)
Expand Down

0 comments on commit 78ccaed

Please sign in to comment.