[system] / trunk / webwork / system / cgi / cgi-scripts / change-password.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/cgi/cgi-scripts/change-password.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (download) (as text) (annotate)
Fri Jun 15 16:24:03 2001 UTC (11 years, 11 months ago) by gage
File size: 3468 byte(s)
modified use lib lines in cgi-scripts, scripts, courseScripts
removed Global.pm updating and use lib line code from system_webwork_setup
modified Global.pm to use webworkConfig (which is not in the repository!)

    1 #!/usr/local/bin/webwork-perl
    2 
    3 ## $Id$
    4 
    5 ## change-passwd.pl
    6 ## password update script for the WeBWorK project
    7 
    8 require 5.001;
    9 use strict;
   10 use lib '.'; use webworkInit; # WeBWorKInitLine
   11 
   12 use Global;
   13 use Auth;
   14 use GDBM_File;
   15 use CGI qw(:standard);
   16 
   17 my $scriptDirectory   = $Global::scriptDirectory;
   18 require "${scriptDirectory}$Global::HTMLglue_pl";
   19 
   20 my $User    = param('user')    || &error_form('No user', 'No user name specified.');
   21 my $Key     = param('key')     || &error_form('No key', 'No session key specified.');
   22 my $Course  = param('course')  || &error_form('No course', 'No course specified.');
   23 
   24 my $Passwd  = param('passwd');
   25 my $Oldpasswd = param('oldpasswd');
   26 my $Check   = param('check');
   27 
   28 # remove any leading/trailing spaces in input
   29 #$Passwd    =~ s|^\s*(.*?)\s*$|$1|;
   30 #$Oldpasswd =~ s|^\s*(.*?)\s*$|$1|;
   31 #$Check     =~ s|^\s*(.*?)\s*$|$1|;
   32 
   33 &Global::getCourseEnvironment($Course);
   34 
   35 my $Passwd_file = &getCoursePasswordFile($Course);
   36 &Global::error("", "Can't read $Passwd_file") unless (-r $Passwd_file);
   37 
   38 my $Key_file    = &getCourseKeyFile($Course);
   39 &Global::error("", "Can't read $Key_file") unless (-r $Key_file);
   40 
   41 
   42 ## make sure user's already been authenticated
   43 &verify_key($User, $Key, $Key_file, $Course);
   44 
   45 ## exit if user is a practice user
   46 ## exit if practice user
   47 if ($User =~ /^$Global::practiceUser/) {
   48     wwerror('Operation not allowed', "practice users are not allowed to change passwords.\nPlease go back and select: Begin Problem Set.");
   49 }
   50 
   51 
   52 ## if all the data's been entered, check it
   53 if ($Oldpasswd && $Passwd && $Check) {
   54 
   55     ## make sure they know their password (and didn't just hit "back" in a browser)
   56     unless (&verify_password($User, $Oldpasswd, $Passwd_file)) {
   57   &error_form("Invalid Password", "Old password isn't correct.");
   58     }
   59 
   60     ## make sure they know what they entered
   61     if ($Passwd ne $Check) {
   62   &error_form("Password Mismatch", "Your passwords don't match.");
   63     }
   64 
   65     ## all's well - set a new password
   66     &new_password($User, $Passwd, $Passwd_file);
   67     &success_form;
   68 }
   69 
   70 ## otherwise print the password change form (again, if necessary)
   71 else {
   72     &change_pw_form;
   73     exit;
   74 }
   75 
   76 
   77 sub change_pw_form {
   78     my $course = shift;
   79 
   80     print &htmlTOP('Change Password Page', $Global::background_plain_url),
   81     hr,
   82     h1('Change Password Page'),
   83     start_form('POST', url),
   84     "Please choose a new password for your ", b($Course),
   85     " account, ", b($User), ".",
   86     p,
   87     i("For your own safety, ", b("DO NOT"), " pick the same password
   88     used for other (e.g. e-mail) accounts!"),
   89 
   90     p,
   91     password_field('oldpasswd', '', 18), " Old password", br,
   92     password_field('passwd', '', 18), " New password", br,
   93     password_field('check', '', 18), " New password (again)", br,
   94     p,
   95     submit('Set your new password'),
   96     hidden('user'),
   97       hidden('key'),
   98       hidden('course'),
   99     end_form, end_html;
  100 }
  101 
  102 
  103 sub success_form {
  104     print &htmlTOP('Password Changed', $Global::background_okay_url),
  105     hr,
  106     h1('Password Changed'),
  107     "Your new password for ", b($Course), " is in effect.",
  108     p,
  109     start_form('POST', "${Global::cgiWebworkURL}login.pl"),
  110     p,"\n",
  111     hidden('course'), "\n", hidden('user'), "\n", hidden('key'),
  112     submit('Continue'),
  113     end_form, end_html;
  114 }
  115 
  116 sub error_form {
  117     my ($title, $msg) = @_;
  118 
  119     print &htmlTOP($title, $Global::background_warn_url),
  120     hr,
  121     h1($title),
  122     $msg,
  123     p,
  124     "Hit the <B>Back</B> button and try again.",
  125     end_form, end_html;
  126     exit;
  127 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9