我已經寫了一個PHP腳本,以允許用戶創建帳戶的郵件服務。現在PHP腳本來更改Ubuntu用戶密碼
shell_exec("sudo useradd -m ".escapeshellcmd($user_name)." -s /sbin/nologin"." -p ".crypt(escapeshellcmd($user_password),"abcd"));
我想允許用戶更改/刪除其密碼/帳戶。我試着用
shell_exec("sudo deluser --remove-all-files -f ".$username);
我不知道如何實現密碼更改。
不幸的是,這些命令似乎沒有工作。我怎樣才能實現這些?
更新:一段代碼來處理密碼更改
case 'change':
$username = $_POST['value'];
$newpwd = $_POST['Pwd'];
// Berry Langerak's code
$out = shell_exec(
sprintf(
"echo '%s:%s' | chpasswd",
escapeshellarg($username),
escapeshellarg($newpwd)
)
);
echo(json_encode($username." password has been updated"));
break;
你可以檢查這個http://stackoverflow.com/questions/127459/using-shell-execpasswd-to-change-a-users-password – leticia
有希望,你的用戶不能被稱爲「; rm -rf/*」 –