[LON-CAPA-cvs] cvs: loncom /enrollment Enrollment.pm /interface domainprefs.pm
raeburn
raeburn at source.lon-capa.org
Tue May 14 09:39:24 EDT 2019
raeburn Tue May 14 13:39:24 2019 EDT
Modified files:
/loncom/enrollment Enrollment.pm
/loncom/interface domainprefs.pm
Log:
- Rules for length and/or characters in a LON-CAPA password (internal auth)
in effect for passwords created by &create_password() in Enrollment.pm
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.52 loncom/enrollment/Enrollment.pm:1.53
--- loncom/enrollment/Enrollment.pm:1.52 Fri Oct 27 13:35:37 2017
+++ loncom/enrollment/Enrollment.pm Tue May 14 13:39:18 2019
@@ -1,5 +1,5 @@
# Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.52 2017/10/27 13:35:37 raeburn Exp $
+# $Id: Enrollment.pm,v 1.53 2019/05/14 13:39:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,7 +31,9 @@
use Apache::lonmsg;
use Apache::lonlocal;
use HTML::Entities;
+use HTML::Parser;
use LONCAPA::Configuration;
+use Math::Random;
use Time::Local;
use lib '/home/httpd/lib/perl';
@@ -586,7 +588,7 @@
# If no account exists and passwords should be generated
if ($auth eq "internal") {
if ($authparam eq '') {
- $authparam = &create_password();
+ $authparam = &create_password($udom);
if ($authparam eq '') {
$authchk = '';
} else {
@@ -950,23 +952,77 @@
}
sub create_password {
- my $passwd = '';
- my @letts = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
- for (my $i=0; $i<8; $i++) {
+ my ($udom) = @_;
+ my %passwdconf = &Apache::lonnet::get_passwdconf($udom);
+ my ($min,$max, at chars);
+ if (ref($passwdconf{'chars'}) eq 'ARRAY') {
+ if ($passwdconf{'min'} =~ /^\d+$/) {
+ $min = $passwdconf{'min'};
+ }
+ if ($passwdconf{'max'} =~ /^\d+$/) {
+ $max = $passwdconf{'max'};
+ }
+ @chars = @{$passwdconf{'chars'}};
+ }
+ my @letts = qw(b c d f g h j k l m n p q r s t v w x y z);
+ my (@included,%reqd);
+ if (@chars) {
+ map { $reqd{$_} = 1; } @chars;
+ }
+ if ($reqd{'uc'}) {
+ my $letter = $letts[int( rand(21) )];
+ $letter =~ tr/a-z/A-Z/;
+ if ($letter ne '') {
+ push(@included,$letter);
+ }
+ }
+ if ($reqd{'lc'}) {
+ my $letter = $letts[int( rand(21) )];
+ if ($letter ne '') {
+ push(@included,$letter);
+ }
+ }
+ if ($reqd{'num'}) {
+ my $number = int( rand(10) );
+ if ($number ne '') {
+ push(@included,$number);
+ }
+ }
+ if ($reqd{'spec'}) {
+ my @specs = qw(! # * & _ - + $);
+ my $special = $specs[int( rand(8) )];
+ if ($special ne '') {
+ push(@included,$special);
+ }
+ }
+ my $start = 0;
+ if (scalar(@included) > 0) {
+ $start = scalar(@included);
+ }
+ my $end = 8;
+ if ($min =~ /^\d+$/) {
+ if ($min > $end) {
+ $end = $min;
+ }
+ }
+ for (my $i=$start; $i<$end; $i++) {
my $lettnum = int (rand 2);
my $item = '';
if ($lettnum) {
- $item = $letts[int( rand(26) )];
+ $item = $letts[int( rand(21) )];
my $uppercase = int(rand 2);
if ($uppercase) {
$item =~ tr/a-z/A-Z/;
}
} else {
$item = int( rand(10) );
- }
- $passwd .= $item;
+ }
+ if ($item ne '') {
+ push(@included,$item);
+ }
}
- return ($passwd);
+ my $passwd = join('',&Math::Random::random_permutation(@included));
+ return $passwd;
}
sub get_courseinfo {
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.360 loncom/interface/domainprefs.pm:1.361
--- loncom/interface/domainprefs.pm:1.360 Fri May 10 14:24:53 2019
+++ loncom/interface/domainprefs.pm Tue May 14 13:39:24 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.360 2019/05/10 14:24:53 raeburn Exp $
+# $Id: domainprefs.pm,v 1.361 2019/05/14 13:39:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -10797,7 +10797,7 @@
my ($configuserok,%currroles);
if ($uhome eq 'no_host') {
srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
- my $configpass = &LONCAPA::Enrollment::create_password();
+ my $configpass = &LONCAPA::Enrollment::create_password($dom);
$configuserok =
&Apache::lonnet::modifyuser($dom,$confname,'','internal',
$configpass,'','','','','',undef,$servadm);
More information about the LON-CAPA-cvs
mailing list