[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonpreferences.pm

raeburn raeburn at source.lon-capa.org
Wed Feb 12 15:29:36 EST 2014


raeburn		Wed Feb 12 20:29:36 2014 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonpreferences.pm 
  Log:
  - Move &des_keys() and &des_crypt() from lonpreferences.pm to createaccount.pm
    to facilitate reuse.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1173 loncom/interface/loncommon.pm:1.1174
--- loncom/interface/loncommon.pm:1.1173	Tue Feb 11 14:29:04 2014
+++ loncom/interface/loncommon.pm	Wed Feb 12 20:29:35 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1173 2014/02/11 14:29:04 kruse Exp $
+# $Id: loncommon.pm,v 1.1174 2014/02/12 20:29:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -75,6 +75,8 @@
 use Text::Aspell;
 use Authen::Captcha;
 use Captcha::reCAPTCHA;
+use Crypt::DES;
+use DynaLoader; # for Crypt::DES version
 
 # ---------------------------------------------- Designs
 use vars qw(%defaultdesign);
@@ -15045,6 +15047,19 @@
     return $captcha_chk;
 }
 
+sub emailusername_info {
+    my @fields = ('lastname','firstname','institution','web','location','officialemail');
+    my %titles = &Apache::lonlocal::texthash (
+                     lastname      => 'Last Name',
+                     firstname     => 'First Name',
+                     institution   => 'School/college/university',
+                     location      => "School's city, state/province, country",
+                     web           => "School's web address",
+                     officialemail => 'E-mail address at institution (if different)',
+                 );
+    return (\@fields,\%titles);
+}
+
 sub cleanup_html {
     my ($incoming) = @_;
     my $outgoing;
@@ -15067,6 +15082,48 @@
     return $outgoing;
 }
 
+# Use:
+#   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
+#
+##################################################
+#          password associated functions         #
+##################################################
+sub des_keys {
+    # Make a new key for DES encryption.
+    # Each key has two parts which are returned separately.
+    # Please note:  Each key must be passed through the &hex function
+    # before it is output to the web browser.  The hex versions cannot
+    # be used to decrypt.
+    my @hexstr=('0','1','2','3','4','5','6','7',
+                '8','9','a','b','c','d','e','f');
+    my $lkey='';
+    for (0..7) {
+        $lkey.=$hexstr[rand(15)];
+    }
+    my $ukey='';
+    for (0..7) {
+        $ukey.=$hexstr[rand(15)];
+    }
+    return ($lkey,$ukey);
+}
+
+sub des_decrypt {
+    my ($key,$cyphertext) = @_;
+    my $keybin=pack("H16",$key);
+    my $cypher;
+    if ($Crypt::DES::VERSION>=2.03) {
+        $cypher=new Crypt::DES $keybin;
+    } else {
+        $cypher=new DES $keybin;
+    }
+    my $plaintext=
+        $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
+    $plaintext.=
+        $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
+    $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
+    return $plaintext;
+}
+
 =pod
 
 =back
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.210 loncom/interface/lonpreferences.pm:1.211
--- loncom/interface/lonpreferences.pm:1.210	Thu Aug 29 12:36:15 2013
+++ loncom/interface/lonpreferences.pm	Wed Feb 12 20:29:36 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.210 2013/08/29 12:36:15 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.211 2014/02/12 20:29:36 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,8 +36,6 @@
 use LONCAPA;
 use Apache::Constants qw(:common);
 use Apache::File;
-use Crypt::DES;
-use DynaLoader; # for Crypt::DES version
 use Apache::loncommon();
 use Apache::lonhtmlcommon();
 use Apache::lonlocal;
@@ -45,50 +43,6 @@
 use LONCAPA::lonauthcgi();
 use LONCAPA();
 
-#
-# Write lonnet::passwd to do the call below.
-# Use:
-#   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
-#
-##################################################
-#          password associated functions         #
-##################################################
-sub des_keys {
-    # Make a new key for DES encryption.
-    # Each key has two parts which are returned separately.
-    # Please note:  Each key must be passed through the &hex function
-    # before it is output to the web browser.  The hex versions cannot
-    # be used to decrypt.
-    my @hexstr=('0','1','2','3','4','5','6','7',
-                '8','9','a','b','c','d','e','f');
-    my $lkey='';
-    for (0..7) {
-        $lkey.=$hexstr[rand(15)];
-    }
-    my $ukey='';
-    for (0..7) {
-        $ukey.=$hexstr[rand(15)];
-    }
-    return ($lkey,$ukey);
-}
-
-sub des_decrypt {
-    my ($key,$cyphertext) = @_;
-    my $keybin=pack("H16",$key);
-    my $cypher;
-    if ($Crypt::DES::VERSION>=2.03) {
-        $cypher=new Crypt::DES $keybin;
-    } else {
-        $cypher=new DES $keybin;
-    }
-    my $plaintext=
-	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
-    $plaintext.=
-	$cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
-    $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
-    return $plaintext;
-}
-
 ################################################################
 #                       Handler subroutines                    #
 ################################################################
@@ -1604,9 +1558,9 @@
     }
     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
     # 
-    $currentpass = &des_decrypt($ckey ,$currentpass);
-    $newpass1    = &des_decrypt($n1key,$newpass1);
-    $newpass2    = &des_decrypt($n2key,$newpass2);
+    $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass);
+    $newpass1    = &Apache::loncommon::des_decrypt($n1key,$newpass1);
+    $newpass2    = &Apache::loncommon::des_decrypt($n2key,$newpass2);
     #
     if ($caller eq 'reset_by_email') {
         my %data = &Apache::lonnet::tmpget($mailtoken);




More information about the LON-CAPA-cvs mailing list