Skip to content

Instantly share code, notes, and snippets.

@mbeijen
Created March 4, 2013 13:39
Show Gist options
  • Select an option

  • Save mbeijen/5082292 to your computer and use it in GitHub Desktop.

Select an option

Save mbeijen/5082292 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# --
# bin/otrs.SetCustomerPassword.pl - Changes or Sets password for a customer
# Copyright (C) 2001-2013 OTRS AG, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# 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 the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . '/Kernel/cpan-lib';
use lib dirname($RealBin) . '/Custom';
use vars qw($VERSION);
$VERSION = qw($Revision: 1.01 $) [1];
use Getopt::Std;
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::CustomerUser;
use Kernel::System::Main;
use Kernel::System::Time;
# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
%CommonObject,
LogPrefix => 'OTRS-otrs.SetCustomerPassword.pl',
);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{CustomerObject} = Kernel::System::CustomerUser->new(%CommonObject);
my %Opts;
getopt( 'h', \%Opts );
if ( $Opts{h} ) {
print "$0 <Revision $VERSION> - set a new customer password\n";
print "Copyright (C) 2001-2013 OTRS AG, http://otrs.com/\n";
print "usage: otrs.SetCustomerPassword user password\n";
exit 1;
}
my $User = shift;
my $Pw = shift;
if ( !$User ) {
print STDERR "ERROR: need user ARG[1]\n";
exit 1;
}
if ( !$Pw ) {
$Pw = $CommonObject{CustomerObject}->GenerateRandomPassword(
Size => 12,
);
}
my %User = $CommonObject{CustomerObject}->CustomerUserDataGet(
User => $User,
);
if ( !$User{UserLogin} ) {
die "No such customer: $User\n";
}
my $Result = $CommonObject{CustomerObject}->SetPassword(
UserLogin => $User,
PW => $Pw,
);
if ( !$Result ) {
die "Failed to set password!\n";
}
print "Set password $Pw for user $User{UserLogin}.\n";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment