7

Let's say I have a user in Phabricator and I need to change his password (for example the email system is out of order and I need to set the password NOW).

How can I do that?

tach
  • 663
  • 12
  • 19

2 Answers2

7

Just met the same situation myself, you can execute a script to recover a user account in phabricator.

bin/auth recover $USERNAME

after execution, a recover URL will be printed in the console, which can be used to reset a new password for the user.

related information: https://secure.phabricator.com/D18901

YJ Park
  • 71
  • 1
  • 3
1

It seems that Phabricator maintainers for some reason believe that administrators should not have full access to the user administration and don't provide tools for such task (e.g. https://stackoverflow.com/a/21249019/754982). One option is to hack the database directly, other is to add the functionality to the account_admin.php tool which used to have this functionality before (https://secure.phabricator.com/D18901?id=45357).

I submit patch for this script, which adds the functionality again. I'm not trying to do PR to the Phabricator codebase, I don't believe it would get accepted.

From 3340df50268d612c16ac17f48f69a9952688f47e Mon Sep 17 00:00:00 2001
From: root <user@localhost>
Date: Sun, 23 Jun 2019 02:44:24 +0200
Subject: [PATCH] Added possibility of changing passwords

---
 scripts/user/account_admin.php | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/scripts/user/account_admin.php b/scripts/user/account_admin.php
index 4e4500a2f..d5aa5f76e 100755
--- a/scripts/user/account_admin.php
+++ b/scripts/user/account_admin.php
@@ -112,6 +112,18 @@ if ($is_new) {
   $create_email = $email;
 }
 
+$changed_pass = false;
+// This disables local echo, so the user's password is not shown as they type
+// it.
+phutil_passthru('stty -echo');
+$password = phutil_console_prompt(
+  pht('Enter a password for this user [blank to leave unchanged]:'));
+phutil_passthru('stty echo');
+if (strlen($password)) {
+  $changed_pass = $password;
+}
+
+
 $is_system_agent = $user->getIsSystemAgent();
 $set_system_agent = phutil_console_confirm(
   pht('Is this user a bot?'),
@@ -148,6 +160,11 @@ if ($is_new) {
   printf($tpl, pht('Email'), '', $create_email);
 }
 
+printf($tpl, pht('Password'), null,
+  ($changed_pass !== false)
+    ? pht('Updated')
+    : pht('Unchanged'));
+
 printf(
   $tpl,
   pht('Bot'),
@@ -200,6 +217,17 @@ $user->openTransaction();
     $editor->updateUser($user, $verify_email);
   }
 
+  if ($changed_pass !== false) {
+    $password_envelope = new PhutilOpaqueEnvelope($changed_pass);
+
+    $account_type = PhabricatorAuthPassword::PASSWORD_TYPE_ACCOUNT;
+    $password_object = PhabricatorAuthPassword::initializeNewPassword($user, $account_type);
+
+    $password_object
+      ->setPassword($password_envelope, $user)
+      ->save();
+  }
+
   $editor->makeSystemAgentUser($user, $set_system_agent);
 
   $xactions = array();
@@ -223,6 +251,7 @@ $user->openTransaction();
 
   $transaction_editor->applyTransactions($user, $xactions);
 
+
 $user->saveTransaction();
 
 echo pht('Saved changes.')."\n";
-- 
2.20.1
tach
  • 663
  • 12
  • 19