#!/usr/bin/env perl ################################################################################ # WeBWorK Online Homework Delivery System # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ # $CVSHeader: webwork-modperl/bin/addcourse,v 1.13 2004/05/22 01:08:08 sh002i Exp $ # # This program is free software; you can redistribute it and/or modify it under # the terms of either: (a) the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any later # version, or (b) the "Artistic License" which comes with this package. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the # Artistic License for more details. ################################################################################ =head1 NAME newpassword - change a users password =head1 SYNOPSIS newpassword COURSEID USERID NEWPASSWORD =head1 DESCRIPTION Change the password for a user. =head1 ARGUMENTS =over =item I The name of the course. =item I The login name of the user you will change the password for. =item I The new password. =back =cut BEGIN { # hide arguments (there could be passwords there!) $0 = "$0"; } use strict; use warnings; BEGIN { die "WEBWORK_ROOT not found in environment.\n" unless exists $ENV{WEBWORK_ROOT}; } use lib "$ENV{WEBWORK_ROOT}/lib"; use WeBWorK::CourseEnvironment; use WeBWorK::DB; use WeBWorK::Utils qw(runtime_use readFile cryptPassword); if((scalar(@ARGV) != 3)) { print "\nSyntax is: newpassword CourseID User NewPassword"; print "\n (e.g. newpassword MAT_123 jjones abracadabra\n\n"; exit(); } ##### get command-line options ##### my $courseID = shift; my $user = shift; my $newP = shift; ##### main function ##### sub dopasswd { my ($db, $user, $newpass) = @_; my $passwordRecord = eval {$db->getPassword($user)}; die "Can't get password for user |$user| $@" if $@ or not defined($passwordRecord); my $cryptedPassword = cryptPassword($newP); $passwordRecord->password($cryptedPassword); eval {$db->putPassword($passwordRecord) }; if ($@) { die "Errors $@ "; } } # bring up a minimal course environment my $ce = WeBWorK::CourseEnvironment->new($ENV{WEBWORK_ROOT}, "FAKE_URL_ROOT", "FAKE_PG_ROOT", $courseID); my $db = new WeBWorK::DB($ce->{dbLayout}); dopasswd($db, $user, $newP); print "Changed password for $user in $courseID\n";