0

I need to do some command lines through a browser. What I need to do in a command-line would be:

$login
<login name>
<password>
$passwd
<old password>
<new password>
<retype new password>

So, how can I do this using the proc_open function? Or should I use another function to do this?


Adam Wright, I've tried your example, but I just can't change users password. do I need to do any other things in the script (besides defining $user, $userPassword and $newPassword)?

Thanks

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
RSilva
  • 6,753
  • 11
  • 43
  • 49

3 Answers3

1

You don't need to issue login to change the password for a user, just give their name to passwd. Using popen (as we don't need to read in this tiny example), something like

$pp = popen("passwd ${user}", "w");
fwrite($pp, $oldPassword . '\n');
fwrite($pp, $newPassword . '\n');
fwrite($pp, $newPassword . '\n');
pclose($pp);

If you want to read the responses, use proc_open, and just read from the stdout handle you're given.

I hope this is all well secured, and that you have a lot of sanitisation on the username.

Adam Wright
  • 48,938
  • 12
  • 131
  • 152
  • This will only work when the php interpreter runs with superuser privileges (only root can change the passwd of an other user). If you don't care about security, you can either set the superuser bit of passwd or use sudo. – jk. Sep 25 '08 at 12:05
1

http://pecl.php.net/package/PAM might be something you can use.
It has a function bool pam_chpass(string $username, string $oldpassword, string $newpassword [, string &$error ]).
But I've never used it.

VolkerK
  • 95,432
  • 20
  • 163
  • 226
1

Found this Change Linux or UNIX system password using PHP script in the internet.

A very detailed description on how to create a website where a user can change his own system password.

jk.
  • 6,388
  • 2
  • 26
  • 21