1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
# --
# Copyright (C) 2001-2017 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::Output::HTML::Preferences::Password;
use strict;
use warnings;
use Kernel::Language qw(Translatable);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::Auth',
'Kernel::System::CustomerAuth',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
for my $Needed (qw(UserID UserObject ConfigItem)) {
die "Got no $Needed!" if !$Self->{$Needed};
}
return $Self;
}
sub Param {
my ( $Self, %Param ) = @_;
# check if we need to show password change option
# define AuthModule for frontend
my $AuthModule = $Self->{ConfigItem}->{Area} eq 'Agent'
? 'AuthModule'
: 'Customer::AuthModule';
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# get auth module
my $Module = $ConfigObject->Get($AuthModule);
my $AuthBackend = $Param{UserData}->{UserAuthBackend};
if ($AuthBackend) {
$Module = $ConfigObject->Get( $AuthModule . $AuthBackend );
}
# return on no pw reset backends
return if $Module =~ /(LDAP|HTTPBasicAuth|Radius)/i;
my @Params;
push(
@Params,
{
%Param,
Key => Translatable('Current password'),
Name => 'CurPw',
Raw => 1,
Block => 'Password'
},
{
%Param,
Key => Translatable('New password'),
Name => 'NewPw',
Raw => 1,
Block => 'Password'
},
{
%Param,
Key => Translatable('Verify password'),
Name => 'NewPw1',
Raw => 1,
Block => 'Password'
},
);
# set the TwoFactorModue setting name depending on the interface
my $AuthTwoFactorModule = $Self->{ConfigItem}->{Area} eq 'Agent'
? 'AuthTwoFactorModule'
: 'Customer::AuthTwoFactorModule';
# show 2 factor password input if we have at least one backend enabled
COUNT:
for my $Count ( '', 1 .. 10 ) {
next COUNT if !$ConfigObject->Get( $AuthTwoFactorModule . $Count );
push @Params, {
%Param,
Key => '2 Factor Token',
Name => 'TwoFactorToken',
Raw => 1,
Block => 'Password',
};
last COUNT;
}
return @Params;
}
sub Run {
my ( $Self, %Param ) = @_;
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# pref update db
return 1 if $ConfigObject->Get('DemoSystem');
# get password from form
my $CurPw;
if ( $Param{GetParam}->{CurPw} && $Param{GetParam}->{CurPw}->[0] ) {
$CurPw = $Param{GetParam}->{CurPw}->[0];
}
my $Pw;
if ( $Param{GetParam}->{NewPw} && $Param{GetParam}->{NewPw}->[0] ) {
$Pw = $Param{GetParam}->{NewPw}->[0];
}
my $Pw1;
if ( $Param{GetParam}->{NewPw1} && $Param{GetParam}->{NewPw1}->[0] ) {
$Pw1 = $Param{GetParam}->{NewPw1}->[0];
}
# get the two factor token from form
my $TwoFactorToken;
if ( $Param{GetParam}->{TwoFactorToken} && $Param{GetParam}->{TwoFactorToken}->[0] ) {
$TwoFactorToken = $Param{GetParam}->{TwoFactorToken}->[0];
}
# define AuthModule for frontend
my $AuthModule = $Self->{ConfigItem}->{Area} eq 'Agent'
? 'Auth'
: 'CustomerAuth';
my $AuthObject = $Kernel::OM->Get( 'Kernel::System::' . $AuthModule );
return 1 if !$AuthObject;
# get layout object
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
# validate current password
if (
!$AuthObject->Auth(
User => $Param{UserData}->{UserLogin},
Pw => $CurPw,
TwoFactorToken => $TwoFactorToken || '',
)
)
{
$Self->{Error} = Translatable('The current password is not correct. Please try again!');
return;
}
# check if pw is true
if ( !$Pw || !$Pw1 ) {
$Self->{Error} = Translatable('Please supply your new password!');
return;
}
# compare pws
if ( $Pw ne $Pw1 ) {
$Self->{Error} = Translatable('Can\'t update password, your new passwords do not match. Please try again!');
return;
}
# check pw
my $Config = $Self->{ConfigItem};
# check if password is not matching PasswordRegExp
if ( $Config->{PasswordRegExp} && $Pw !~ /$Config->{PasswordRegExp}/ ) {
$Self->{Error} = Translatable('Can\'t update password, it contains invalid characters!');
return;
}
# check min size of password
if ( $Config->{PasswordMinSize} && length $Pw < $Config->{PasswordMinSize} ) {
$Self->{Error} = Translatable(
'Can\'t update password, it must be at least %s characters long!',
$Config->{PasswordMinSize}
);
return;
}
# check min 2 lower and 2 upper char
if (
$Config->{PasswordMin2Lower2UpperCharacters}
&& ( $Pw !~ /[A-Z].*[A-Z]/ || $Pw !~ /[a-z].*[a-z]/ )
)
{
$Self->{Error}
= Translatable('Can\'t update password, it must contain at least 2 lowercase and 2 uppercase characters!');
return;
}
# check min 1 digit password
if ( $Config->{PasswordNeedDigit} && $Pw !~ /\d/ ) {
$Self->{Error} = Translatable('Can\'t update password, it must contain at least 1 digit!');
return;
}
# check min 2 char password
if ( $Config->{PasswordMin2Characters} && $Pw !~ /[A-z][A-z]/ ) {
$Self->{Error} = Translatable('Can\'t update password, it must contain at least 2 characters!');
return;
}
# set new password
my $Success = $Self->{UserObject}->SetPassword(
UserLogin => $Param{UserData}->{UserLogin},
PW => $Pw,
);
return if !$Success;
$Self->{Message} = Translatable('Preferences updated successfully!');
return 1;
}
sub Error {
my ( $Self, %Param ) = @_;
return $Self->{Error} || '';
}
sub Message {
my ( $Self, %Param ) = @_;
return $Self->{Message} || '';
}
1;
|