[LON-CAPA-cvs] cvs: loncom /interface createaccount.pm loncommon.pm lonuserutils.pm
raeburn
raeburn at source.lon-capa.org
Sun Feb 13 20:15:24 EST 2022
raeburn Mon Feb 14 01:15:24 2022 EDT
Modified files:
/loncom/interface loncommon.pm lonuserutils.pm createaccount.pm
Log:
- Move &passwd_validation_js() to loncommon.pm to facilitate re-use.
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1375 loncom/interface/loncommon.pm:1.1376
--- loncom/interface/loncommon.pm:1.1375 Tue Jan 18 21:03:15 2022
+++ loncom/interface/loncommon.pm Mon Feb 14 01:15:24 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1375 2022/01/18 21:03:15 raeburn Exp $
+# $Id: loncommon.pm,v 1.1376 2022/02/14 01:15:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3648,6 +3648,137 @@
return $warning;
}
+sub passwd_validation_js {
+ my ($currpasswdval,$domain) = @_;
+ my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
+ my ($min,$max, at chars,$numrules,$intargjs,%alert);
+ $numrules = 0;
+ $min = $Apache::lonnet::passwdmin;
+ if (ref($passwdconf{'chars'}) eq 'ARRAY') {
+ if ($passwdconf{'min'} =~ /^\d+$/) {
+ if ($passwdconf{'min'} > $min) {
+ $min = $passwdconf{'min'};
+ }
+ }
+ if ($passwdconf{'max'} =~ /^\d+$/) {
+ $max = $passwdconf{'max'};
+ $numrules ++;
+ }
+ @chars = @{$passwdconf{'chars'}};
+ if (@chars) {
+ $numrules ++;
+ }
+ }
+ if ($min > 0) {
+ $numrules ++;
+ }
+ if (($min > 0) || ($max ne '') || (@chars > 0)) {
+ my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
+ if ($min) {
+ $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
+ }
+ if ($max) {
+ $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
+ }
+ my (@charalerts, at charrules);
+ if (@chars) {
+ if (grep(/^uc$/, at chars)) {
+ push(@charalerts,&mt('contain at least one upper case letter'));
+ push(@charrules,'uc');
+ }
+ if (grep(/^lc$/, at chars)) {
+ push(@charalerts,&mt('contain at least one lower case letter'));
+ push(@charrules,'lc');
+ }
+ if (grep(/^num$/, at chars)) {
+ push(@charalerts,&mt('contain at least one number'));
+ push(@charrules,'num');
+ }
+ if (grep(/^spec$/, at chars)) {
+ push(@charalerts,&mt('contain at least one non-alphanumeric'));
+ push(@charrules,'spec');
+ }
+ }
+ $intargjs = qq| var rulesmsg = '';\n|.
+ qq| var currpwval = $currpasswdval;\n|;
+ if ($min) {
+ $intargjs .= qq|
+ if (currpwval.length < $min) {
+ rulesmsg += ' - $alert{min}';
+ }
+|;
+ }
+ if ($max) {
+ $intargjs .= qq|
+ if (currpwval.length > $max) {
+ rulesmsg += ' - $alert{max}';
+ }
+|;
+ }
+ if (@chars > 0) {
+ my $charrulestr = '"'.join('","', at charrules).'"';
+ my $charalertstr = '"'.join('","', at charalerts).'"';
+ $intargjs .= qq| var brokerules = new Array();\n|.
+ qq| var charrules = new Array($charrulestr);\n|.
+ qq| var charalerts = new Array($charalertstr);\n|;
+ my %rules;
+ map { $rules{$_} = 1; } @chars;
+ if ($rules{'uc'}) {
+ $intargjs .= qq|
+ var ucRegExp = /[A-Z]/;
+ if (!ucRegExp.test(currpwval)) {
+ brokerules.push('uc');
+ }
+|;
+ }
+ if ($rules{'lc'}) {
+ $intargjs .= qq|
+ var lcRegExp = /[a-z]/;
+ if (!lcRegExp.test(currpwval)) {
+ brokerules.push('lc');
+ }
+|;
+ }
+ if ($rules{'num'}) {
+ $intargjs .= qq|
+ var numRegExp = /[0-9]/;
+ if (!numRegExp.test(currpwval)) {
+ brokerules.push('num');
+ }
+|;
+ }
+ if ($rules{'spec'}) {
+ $intargjs .= q|
+ var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
+ if (!specRegExp.test(currpwval)) {
+ brokerules.push('spec');
+ }
+|;
+ }
+ $intargjs .= qq|
+ if (brokerules.length > 0) {
+ for (var i=0; i<brokerules.length; i++) {
+ for (var j=0; j<charrules.length; j++) {
+ if (brokerules[i] == charrules[j]) {
+ rulesmsg += ' - '+charalerts[j]+'\\n';
+ break;
+ }
+ }
+ }
+ }
+|;
+ }
+ $intargjs .= qq|
+ if (rulesmsg != '') {
+ rulesmsg = '$alertmsg'+rulesmsg;
+ alert(rulesmsg);
+ return false;
+ }
+|;
+ }
+ return ($numrules,$intargjs);
+}
+
###############################################################
## Get Kerberos Defaults for Domain ##
###############################################################
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.209 loncom/interface/lonuserutils.pm:1.210
--- loncom/interface/lonuserutils.pm:1.209 Tue Aug 24 00:15:02 2021
+++ loncom/interface/lonuserutils.pm Mon Feb 14 01:15:24 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.209 2021/08/24 00:15:02 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.210 2022/02/14 01:15:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -532,7 +532,7 @@
END
} else {
my ($numrules,$intargjs) =
- &passwd_validation_js('vf.elements[current.argfield].value',$domain);
+ &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
$auth_checks .= (<<END);
foundatype=1;
if (current.argfield == null || current.argfield == '') {
@@ -653,137 +653,6 @@
return $result;
}
-sub passwd_validation_js {
- my ($currpasswdval,$domain) = @_;
- my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
- my ($min,$max, at chars,$numrules,$intargjs,%alert);
- $numrules = 0;
- $min = $Apache::lonnet::passwdmin;
- if (ref($passwdconf{'chars'}) eq 'ARRAY') {
- if ($passwdconf{'min'} =~ /^\d+$/) {
- if ($passwdconf{'min'} > $min) {
- $min = $passwdconf{'min'};
- }
- }
- if ($passwdconf{'max'} =~ /^\d+$/) {
- $max = $passwdconf{'max'};
- $numrules ++;
- }
- @chars = @{$passwdconf{'chars'}};
- if (@chars) {
- $numrules ++;
- }
- }
- if ($min > 0) {
- $numrules ++;
- }
- if (($min > 0) || ($max ne '') || (@chars > 0)) {
- my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
- if ($min) {
- $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
- }
- if ($max) {
- $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
- }
- my (@charalerts, at charrules);
- if (@chars) {
- if (grep(/^uc$/, at chars)) {
- push(@charalerts,&mt('contain at least one upper case letter'));
- push(@charrules,'uc');
- }
- if (grep(/^lc$/, at chars)) {
- push(@charalerts,&mt('contain at least one lower case letter'));
- push(@charrules,'lc');
- }
- if (grep(/^num$/, at chars)) {
- push(@charalerts,&mt('contain at least one number'));
- push(@charrules,'num');
- }
- if (grep(/^spec$/, at chars)) {
- push(@charalerts,&mt('contain at least one non-alphanumeric'));
- push(@charrules,'spec');
- }
- }
- $intargjs = qq| var rulesmsg = '';\n|.
- qq| var currpwval = $currpasswdval;\n|;
- if ($min) {
- $intargjs .= qq|
- if (currpwval.length < $min) {
- rulesmsg += ' - $alert{min}';
- }
-|;
- }
- if ($max) {
- $intargjs .= qq|
- if (currpwval.length > $max) {
- rulesmsg += ' - $alert{max}';
- }
-|;
- }
- if (@chars > 0) {
- my $charrulestr = '"'.join('","', at charrules).'"';
- my $charalertstr = '"'.join('","', at charalerts).'"';
- $intargjs .= qq| var brokerules = new Array();\n|.
- qq| var charrules = new Array($charrulestr);\n|.
- qq| var charalerts = new Array($charalertstr);\n|;
- my %rules;
- map { $rules{$_} = 1; } @chars;
- if ($rules{'uc'}) {
- $intargjs .= qq|
- var ucRegExp = /[A-Z]/;
- if (!ucRegExp.test(currpwval)) {
- brokerules.push('uc');
- }
-|;
- }
- if ($rules{'lc'}) {
- $intargjs .= qq|
- var lcRegExp = /[a-z]/;
- if (!lcRegExp.test(currpwval)) {
- brokerules.push('lc');
- }
-|;
- }
- if ($rules{'num'}) {
- $intargjs .= qq|
- var numRegExp = /[0-9]/;
- if (!numRegExp.test(currpwval)) {
- brokerules.push('num');
- }
-|;
- }
- if ($rules{'spec'}) {
- $intargjs .= q|
- var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
- if (!specRegExp.test(currpwval)) {
- brokerules.push('spec');
- }
-|;
- }
- $intargjs .= qq|
- if (brokerules.length > 0) {
- for (var i=0; i<brokerules.length; i++) {
- for (var j=0; j<charrules.length; j++) {
- if (brokerules[i] == charrules[j]) {
- rulesmsg += ' - '+charalerts[j]+'\\n';
- break;
- }
- }
- }
- }
-|;
- }
- $intargjs .= qq|
- if (rulesmsg != '') {
- rulesmsg = '$alertmsg'+rulesmsg;
- alert(rulesmsg);
- return false;
- }
-|;
- }
- return ($numrules,$intargjs);
-}
-
###############################################################
###############################################################
sub upload_manager_javascript_forward_associate {
@@ -6535,7 +6404,7 @@
$finish = "document.$formname.submit();";
}
my ($numrules,$intargjs) =
- &passwd_validation_js('argpicked',$domain);
+ &Apache::loncommon::passwd_validation_js('argpicked',$domain);
my $outcome = <<"ENDSCRIPT";
function auth_check() {
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.85 loncom/interface/createaccount.pm:1.86
--- loncom/interface/createaccount.pm:1.85 Fri Dec 10 04:14:52 2021
+++ loncom/interface/createaccount.pm Mon Feb 14 01:15:24 2022
@@ -4,7 +4,7 @@
# kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as
# username may be processed automatically, or may be queued for approval.
#
-# $Id: createaccount.pm,v 1.85 2021/12/10 04:14:52 raeburn Exp $
+# $Id: createaccount.pm,v 1.86 2022/02/14 01:15:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,7 +37,6 @@
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhtmlcommon;
-use Apache::lonuserutils;
use Apache::lonlocal;
use Apache::lonauth;
use Apache::resetpw;
@@ -528,7 +527,7 @@
my $mismatchpass = &mt('The passwords you entered did not match.')."\n".
&mt('Please try again.');
my ($numrules,$intargjs) =
- &Apache::lonuserutils::passwd_validation_js('upass',$domain);
+ &Apache::loncommon::passwd_validation_js('upass',$domain);
&js_escape(\$nopass);
&js_escape(\$mismatchpass);
my $js = <<"ENDSCRIPT";
More information about the LON-CAPA-cvs
mailing list