I have written a php script to allow users to create accounts for mailing service.
shell_exec("sudo useradd -m ".escapeshellcmd($user_name)." -s /sbin/nologin"." -p ".crypt(escapeshellcmd($user_password),"abcd"));
Now I would like to allow users to change/delete their password/account. I tried using
shell_exec("sudo deluser --remove-all-files -f ".$username);
I have no idea how to implement password changing.
Unfortunately the commands doesn't seem to be working. How can I implement these?
Update: Piece of code to handle password change
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;