--- loncom/interface/lonuserutils.pm	2020/04/05 20:08:52	1.206
+++ loncom/interface/lonuserutils.pm	2022/11/17 19:07:21	1.211
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.206 2020/04/05 20:08:52 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.211 2022/11/17 19:07:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -532,7 +532,7 @@ END
 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 == '') {
@@ -543,13 +543,15 @@ END
             case 'krb':
                 alertmsg = '$alert{'krb'}';
                 break;
-            case 'loc':
             case 'int':
                 alertmsg = '$alert{'ipass'}';
                 break;
             case 'fsys':
                 alertmsg = '$alert{'ipass'}';
                 break;
+            case 'loc':
+                alertmsg = '';
+                break;
             case 'lti':
             default:
                 alertmsg = '';
@@ -651,137 +653,6 @@ END
     return $result;
 }
 
-sub passwd_validation_js {
-    my ($currpasswdval,$domain) = @_;
-    my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
-    my ($min,$max,@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,@charrules);
-        if (@chars) {
-            if (grep(/^uc$/,@chars)) {
-                push(@charalerts,&mt('contain at least one upper case letter'));
-                push(@charrules,'uc');
-            }
-            if (grep(/^lc$/,@chars)) {
-                push(@charalerts,&mt('contain at least one lower case letter'));
-                push(@charrules,'lc');
-            }
-            if (grep(/^num$/,@chars)) {
-                push(@charalerts,&mt('contain at least one number'));
-                push(@charrules,'num');
-            }
-            if (grep(/^spec$/,@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('","',@charrules).'"';
-                my $charalertstr = '"'.join('","',@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 {
@@ -1709,10 +1580,11 @@ sub my_custom_roles {
     my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
     foreach my $key (keys(%rolehash)) {
         if ($key=~/^rolesdef\_(\w+)$/) {
+            my $role = $1;
             if ($crstype eq 'Community') {
                 next if ($rolehash{$key} =~ /bre\&S/); 
             }
-            $returnhash{$1}=$1;
+            $returnhash{$role}=$role;
         }
     }
     return %returnhash;
@@ -5189,7 +5061,11 @@ sub passwdrule_alerts {
             my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
             $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
             if ($showrules{'min'}) {
-                $warning .= '<li>'.&mt('minimum [quant,_1,character]',$passwdconf{'min'}).'</li>';
+                my $min = $passwdconf{'min'};
+                if ($min eq '') {
+                    $min = $Apache::lonnet::passwdmin;
+                }
+                $warning .= '<li>'.&mt('minimum [quant,_1,character]',$min).'</li>';
             }
             if ($showrules{'max'}) {
                 $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
@@ -6318,8 +6194,9 @@ sub get_permission {
         }
     }
     my $allowed = 0;
-    foreach my $perm (values(%permission)) {
-        if ($perm) { $allowed=1; last; }
+    foreach my $key (keys(%permission)) {
+        next if (($key eq 'owner') || ($key eq 'co-owner'));
+        if ($permission{$key}) { $allowed=1; last; }
     }
     return (\%permission,$allowed);
 }
@@ -6528,7 +6405,7 @@ sub verify_authen {
         $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() {