Please help me as I have been trying to get this to work for two days.
I have a text file which has the array to define username and passwords.
$USERS['user'] = 'pass1';
I am trying to make a PHP to change this password
//name - call_pwd.php
$commandline='./change_password ' . $_SESSION["logged"] . " " . $_POST["old_password"] . " " . $_POST["new_password"]
$output = shell_exec("$commandline");
Here is the bash file I made to change this password. Because I am not good at it I have to use so many variables to make it easily.
#!/bin/bash
#name - change_password
username=`echo "$1"`
old_password=`echo "$2"`
new_password=`echo "$3"`
old_string=`echo "\['$username'\] = '$old_password'"`
new_string=`echo "['$username'] = '$new_password'"`
sed -i "s/${old_string}/${new_string}/" passwords.php
if [ "$?" == 0 ]
then
echo "Password changed Successfully."
else
echo "Could not change password, try again."
fi
When I run this script from the root prompt it works fine and changes the password. But from PHP it won't work. It keeps giving me the message "Could not change password, try again."
As I read " and ' needs to be escaped if you want to use sed with php and I tried that with
sed -i \"s/${old_string}/${new_string}/\" passwords.php
sed -i \""s/${old_string}/${new_string}/\"" passwords.php
The permissions on passwords.php is full permission for all users. I have also tried putting absolute paths everywhere but that also didn't work.
The $output variable on my call_pwd.php comes out as when I echo $commandline $old_string and $new_string
change_password user pass1 pass2
\['user'\] = 'pass1'
['user'] = 'pass2'
Could not change password, try again.
Please help me. Thanks. Apologies for such a long post.