1

I have created a new user and password. Now I need to change the username and password from the web page. I am able to change the username using usermod. But I am not able to change to password using the passwd command. Here the code:

shell_exec('(echo "'.$FTPpassword.'";sleep 1; echo "'.$FTPpassword.'") | passwd $FTPUserName');

Instead of $FTPUserName , if I send username test as :

shell_exec('(echo "'.$FTPpassword.'";sleep 1; echo "'.$FTPpassword.'") | passwd test');

it is updating password of the user "test". Anyone know how to change the password of a user using shell_exec?

Regards,
Sowmya

user12345
  • 357
  • 2
  • 3
  • 11

1 Answers1

0

Use --stdin flag. This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.

shell_exec("echo $FTPpassword | passwd $FTPUserName --stdin");

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127