Reputation: 4164
I'm doing this:
$user = 'kevin';
$pass = 'nivek';
shell_exec('echo -e "' . $pass . '\n' . $pass . '" | sudo passwd ' . $user);`
But when I execute this, I get this error:
Enter new UNIX password: Retype new UNIX password: Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged
Why? How can I solve this and how can I hide the output from passwd?
Upvotes: 0
Views: 554
Reputation: 21989
You can use the following code:
$user = 'kevin';
$pass = 'nivek';
shell_exec('echo -e "' . $pass . '" | sudo passwd --stdin ' . $user);
That appears to work for me (although tested without sudo, you may need the second).
I'm not sure that sudo would even work.
Upvotes: 1
Reputation: 26309
Use --stdin for passwd to read from standard input. Then you can pipe the password.
Upvotes: 2