[system] / trunk / webwork-modperl / bin / newpassword Repository:
ViewVC logotype

View of /trunk/webwork-modperl/bin/newpassword

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3973 - (download) (annotate)
Wed Jan 25 23:13:56 2006 UTC (7 years, 3 months ago) by sh002i
File size: 2601 byte(s)
forward-port from rel-2-2-dev: (update copyright date range -- 2000-2006.
this is probably overkill, since there are some files that were created
after 2000 and some files that were last modified before 2006.)

    1 #!/usr/bin/env perl
    2 ################################################################################
    3 # WeBWorK Online Homework Delivery System
    4 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
    5 # $CVSHeader: webwork2/bin/newpassword,v 1.2 2004/09/23 16:53:25 sh002i Exp $
    6 # 
    7 # This program is free software; you can redistribute it and/or modify it under
    8 # the terms of either: (a) the GNU General Public License as published by the
    9 # Free Software Foundation; either version 2, or (at your option) any later
   10 # version, or (b) the "Artistic License" which comes with this package.
   11 # 
   12 # This program is distributed in the hope that it will be useful, but WITHOUT
   13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   14 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   15 # Artistic License for more details.
   16 ################################################################################
   17 
   18 =head1 NAME
   19 
   20 newpassword - change a users password
   21 
   22 =head1 SYNOPSIS
   23 
   24  newpassword COURSEID USERID NEWPASSWORD
   25 
   26 =head1 DESCRIPTION
   27 
   28 Change the password for a user.
   29 
   30 =head1 ARGUMENTS
   31 
   32 =over
   33 
   34 =item I<COURSEID>
   35 
   36 The name of the course.
   37 
   38 =item I<USERID>
   39 
   40 The login name of the user you will change the password for.
   41 
   42 =item I<NEWPASSWORD>
   43 
   44 The new password.
   45 
   46 =back
   47 
   48 =cut
   49 
   50 BEGIN {
   51 	# hide arguments (there could be passwords there!)
   52 	$0 = "$0";
   53 }
   54 
   55 use strict;
   56 use warnings;
   57 
   58 BEGIN {
   59 	die "WEBWORK_ROOT not found in environment.\n"
   60 		unless exists $ENV{WEBWORK_ROOT};
   61 }
   62 
   63 use lib "$ENV{WEBWORK_ROOT}/lib";
   64 use WeBWorK::CourseEnvironment;
   65 use WeBWorK::DB;
   66 use WeBWorK::Utils qw(runtime_use readFile cryptPassword);
   67 
   68 if((scalar(@ARGV) != 3)) {
   69   print "\nSyntax is: newpassword CourseID User NewPassword";
   70   print "\n    (e.g.  newpassword MAT_123 jjones abracadabra\n\n";
   71   exit();
   72 }
   73 
   74 ##### get command-line options #####
   75 
   76 my $courseID = shift;
   77 my $user = shift;
   78 my $newP = shift;
   79 
   80 ##### main function #####
   81 
   82 sub dopasswd {
   83   my ($db, $user, $newpass) = @_;
   84   my $passwordRecord = eval {$db->getPassword($user)};
   85   die "Can't get password for user |$user| $@" if $@ or not defined($passwordRecord);
   86   my $cryptedPassword = cryptPassword($newP);
   87   $passwordRecord->password($cryptedPassword);
   88   eval {$db->putPassword($passwordRecord) };
   89   if ($@) {
   90     die "Errors $@ ";
   91   }
   92 }
   93 
   94 # bring up a minimal course environment
   95 my $ce = WeBWorK::CourseEnvironment->new({
   96 	webwork_dir => $ENV{WEBWORK_ROOT},
   97 	courseName => $courseID
   98 });
   99 
  100 my $db = new WeBWorK::DB($ce->{dbLayout});
  101 
  102 dopasswd($db, $user, $newP);
  103 print "Changed password for $user in $courseID\n";

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9