Commit 19d20ef6 authored by Simon Green's avatar Simon Green

Bug 670669 - Changing the e-mail address under account prefs does not require…

Bug 670669 - Changing the e-mail address under account prefs does not require current password if can_change_password is false r=dkl, a=simon
parent d3a74a92
...@@ -2357,6 +2357,19 @@ sub account_ip_login_failures { ...@@ -2357,6 +2357,19 @@ sub account_ip_login_failures {
return $self->{account_ip_login_failures}; return $self->{account_ip_login_failures};
} }
sub check_current_password {
my $self = shift;
my $password = shift || ThrowUserError("current_password_required");
my $cryptpwd
= $self->cryptpassword || ThrowCodeError("unable_to_retrieve_password");
if (bz_crypt($password, $cryptpwd) ne $cryptpwd) {
ThrowUserError("current_password_incorrect");
}
}
############### ###############
# Subroutines # # Subroutines #
############### ###############
...@@ -3103,6 +3116,11 @@ set_groups. ...@@ -3103,6 +3116,11 @@ set_groups.
C<bool> - Sets C<disable_mail> to the inverse of the boolean provided. C<bool> - Sets C<disable_mail> to the inverse of the boolean provided.
=item C<check_current_password>
C<string> - Throws an error if the supplied password does not match the
user's current password.
=back =back
=head1 CLASS FUNCTIONS =head1 CLASS FUNCTIONS
......
...@@ -1478,11 +1478,11 @@ ...@@ -1478,11 +1478,11 @@
See the list of available <a href="describekeywords.cgi?show_inactive_keywords=1">keywords</a>. See the list of available <a href="describekeywords.cgi?show_inactive_keywords=1">keywords</a>.
[% END %] [% END %]
[% ELSIF error == "old_password_incorrect" %] [% ELSIF error == "current_password_incorrect" %]
[% title = "Incorrect Password" %] [% title = "Incorrect Password" %]
You did not enter your current password correctly. You did not enter your current password correctly.
[% ELSIF error == "old_password_required" %] [% ELSIF error == "current_password_required" %]
[% title = "Old Password Required" %] [% title = "Old Password Required" %]
You must enter your old password to change your email address. You must enter your old password to change your email address.
......
...@@ -210,14 +210,11 @@ sub changeEmail { ...@@ -210,14 +210,11 @@ sub changeEmail {
$dbh->bz_start_transaction(); $dbh->bz_start_transaction();
my $user = Bugzilla::User->check({ id => $userid }); my $user = Bugzilla::User->check({ id => $userid });
my $realpassword = $user->cryptpassword;
my $cgipassword = $cgi->param('password'); my $cgipassword = $cgi->param('password');
# Make sure the user who wants to change the email address # Make sure the user who wants to change the email address
# is the real account owner. # is the real account owner.
if (bz_crypt($cgipassword, $realpassword) ne $realpassword) { $user->check_current_password($cgipassword);
ThrowUserError("old_password_incorrect");
}
# The new email address should be available as this was # The new email address should be available as this was
# confirmed initially so cancel token if it is not still available # confirmed initially so cancel token if it is not still available
......
...@@ -74,29 +74,24 @@ sub SaveAccount { ...@@ -74,29 +74,24 @@ sub SaveAccount {
my $user = Bugzilla->user; my $user = Bugzilla->user;
my $oldpassword = $cgi->param('old_password'); my $oldpassword = $cgi->param('old_password');
my $verified_password;
my $pwd1 = $cgi->param('new_password1'); my $pwd1 = $cgi->param('new_password1');
my $pwd2 = $cgi->param('new_password2'); my $pwd2 = $cgi->param('new_password2');
my $new_login_name = trim($cgi->param('new_login_name')); my $new_login_name = trim($cgi->param('new_login_name'));
if ($user->authorizer->can_change_password if ($user->authorizer->can_change_password
&& ($oldpassword ne "" || $pwd1 ne "" || $pwd2 ne "")) && ($pwd1 ne "" || $pwd2 ne ""))
{ {
my $oldcryptedpwd = $user->cryptpassword; $user->check_current_password($oldpassword);
$oldcryptedpwd || ThrowCodeError("unable_to_retrieve_password"); $verified_password = 1;
if (bz_crypt($oldpassword, $oldcryptedpwd) ne $oldcryptedpwd) { $pwd1 || ThrowUserError("new_password_missing");
ThrowUserError("old_password_incorrect"); validate_password($pwd1, $pwd2);
}
if ($pwd1 ne "" || $pwd2 ne "") {
$pwd1 || ThrowUserError("new_password_missing");
validate_password($pwd1, $pwd2);
if ($oldpassword ne $pwd1) { if ($oldpassword ne $pwd1) {
$user->set_password($pwd1); $user->set_password($pwd1);
# Invalidate all logins except for the current one # Invalidate all logins except for the current one
Bugzilla->logout(LOGOUT_KEEP_CURRENT); Bugzilla->logout(LOGOUT_KEEP_CURRENT);
}
} }
} }
...@@ -105,7 +100,7 @@ sub SaveAccount { ...@@ -105,7 +100,7 @@ sub SaveAccount {
&& $new_login_name) && $new_login_name)
{ {
if ($user->login ne $new_login_name) { if ($user->login ne $new_login_name) {
$oldpassword || ThrowUserError("old_password_required"); $verified_password || $user->check_current_password($oldpassword);
# Block multiple email changes for the same user. # Block multiple email changes for the same user.
if (Bugzilla::Token::HasEmailChangeToken($user->id)) { if (Bugzilla::Token::HasEmailChangeToken($user->id)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment