Skip to content

Commit

Permalink
passwd: Prompt for the current password before setting new password
Browse files Browse the repository at this point in the history
This changes passwd to authenticate non-root users before prompting for
new password.
  • Loading branch information
brapru authored and awesomekling committed Jun 17, 2021
1 parent 96588ad commit b0f8bcc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Userland/Utilities/passwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ int main(int argc, char** argv)
} else if (unlock) {
target_account.set_password_enabled(true);
} else {
if (current_uid != 0) {
auto current_password = Core::get_password("Current password: ");
if (current_password.is_error()) {
warnln("{}", current_password.error());
return 1;
}

if (!target_account.authenticate(current_password.value().characters())) {
warnln("Incorrect or disabled password.");
return 1;
}
}

auto new_password = Core::get_password("New password: ");
if (new_password.is_error()) {
warnln("{}", new_password.error());
Expand Down

0 comments on commit b0f8bcc

Please sign in to comment.