function prompt_silent($prompt) { $command = "/usr/bin/env bash -c 'echo OK'"; if (rtrim(shell_exec($command)) !== 'OK') { script_error("Can't invoke bash"); } $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'"; $password = rtrim(shell_exec($command)); echo "\n"; return $password; }
#!/usr/bin/php <?php require_once __DIR__ . '/init.php'; /** * @see http://httpd.apache.org/docs/2.2/misc/password_encryptions.html */ function hash_password($password) { return '{SHA}' . base64_encode(sha1($password, TRUE)); } count($argv) >= 2 or script_error("Need one argument as the username"); $username = $argv[1]; $password = prompt_silent("Enter New Password: "******"Enter New Password (again): "); if ($password != $repeat_password) { script_error('Repeat password mismatch'); } try { $user = new User($username); $user->setPassword(hash_password($password)); $user->store(); echo "Password reset successfully\n"; } catch (fNotFoundException $e) { script_error("User {$username} doesn't exist"); }