[open-ils-commits] r16162 - branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 7 17:07:08 EDT 2010
Author: dbs
Date: 2010-04-07 17:07:02 -0400 (Wed, 07 Apr 2010)
New Revision: 16162
Modified:
branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
Refactor password strength checks in O:A:Actor into separate functions
Fix up the JavaScript regex-based path along the way
Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2010-04-07 20:14:56 UTC (rev 16161)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2010-04-07 21:07:02 UTC (rev 16162)
@@ -3518,41 +3518,10 @@
my $pw_regex = $U->ou_ancestor_setting_value($user->home_ou, 'global.password_regex');
my $is_strong = 'false';
- if (!$pw_regex) {
- # Use the default set of checks
- if ((length($password) < 7)
- or ($password !~ m/.*\d+.*/)
- or ($password !~ m/.*[A-Za-z]+.*/)) {
- # Still false!
- } else {
- $is_strong = 'true';
- }
+ if ($pw_regex) {
+ $is_strong = check_password_strength_javascript($password, $pw_regex);
} else {
- # The password regex is for JavaScript, so we have to use SpiderMonkey to eval it
- my $js = JavaScript::SpiderMonkey->new();
- $js->init();
- $js->property_by_path('pw.is_strong', 'false');
- $js->property_by_path('pw.password', $password);
- $js->property_by_path('pw.regex', $pw_regex || 'blank');
-
- my $pw_script = << 'PWCHECK';
- if (pw.regex != 'blank') {
- if (pw.password.match(new RegExp(pwregex))) {
- pw.is_strong = 'true';
- }
- } else {
- } while(0);
- }
-PWCHECK
-
- my $rc = $js->eval($pw_script);
- if (!$rc) {
- $logger->error("Error interpreting JavaScript while checking password strength: %s", $@);
- }
-
- # Get the value of a property set in JS
- $is_strong = $js->property_get('pw.is_strong');
- $js->destroy();
+ $is_strong = check_password_strength_default($password);
}
if ($is_strong eq 'false') {
@@ -3572,4 +3541,45 @@
return 1;
}
+sub check_password_strength_default {
+ my $password = shift;
+ # Use the default set of checks
+ if ( (length($password) < 7) or
+ ($password !~ m/.*\d+.*/) or
+ ($password !~ m/.*[A-Za-z]+.*/)
+ ) {
+ return 'false';
+ }
+ return 'true';
+}
+
+sub check_password_strength_javascript {
+ my ($password, $pw_regex) = @_;
+
+ # The password regex is for JavaScript, so we have to use SpiderMonkey to eval it
+ my $js = JavaScript::SpiderMonkey->new();
+ $js->init();
+ $js->property_by_path('pw.is_strong', 'false');
+ $js->property_by_path('pw.password', $password);
+ $js->property_by_path('pw.regex', $pw_regex);
+
+ my $pw_script = << 'PWCHECK';
+ if (pw.password.match(new RegExp(pw.regex))) {
+ pw.is_strong = 'true';
+ }
+PWCHECK
+
+ my $rc = $js->eval($pw_script);
+ if (!$rc) {
+ $logger->error("Error interpreting JavaScript while checking password strength");
+ $logger->error($@);
+ }
+
+ # Get the value of a property set in JS
+ my $result = $js->property_get('pw.is_strong');
+ $js->destroy();
+
+ return $result;
+}
+
1;
More information about the open-ils-commits
mailing list