I'm trying to update user password from an external script. I use this following script to add user:
$login = $_POST['login'];
$password = $_POST['password'];
//Generate a random string
$salt = genRandomPassword();
//$pass is the encripted password
$pass= md5(stripslashes($password).$salt) .'.'.$salt;
// Insert columns.
$columns = array('name', 'username', 'email', 'password');
// Insert values.
$values = array($db->quote($name) , $db->quote($login),
$db->quote($email), $db->quote($pass));
$query = $db->getQuery(true);
// Prepare the insert query.
$query
->insert($db->quoteName(T_USERS)) //T_USERS = users table
->columns($db->quoteName($columns))
->values(implode(',', $values));
It's work fine and users can login well. But when I update the password with this following script:
//random string
$salt = genRandomPassword();
//$pass is the encripted password
$pass= md5(stripslashes($password).$salt) .'.'.$salt;
$fields = array(
$db->quoteName('password') . ' = ' . $db->quote($pass)
);
$conditions = array($db->quoteName('id') . ' = ' . $session->get('user_id'));
$query = $db->getQuery(true);
$query->update(T_USERS)->set($fields)->where($conditions);
$db->setQuery($query);
$db->execute();
The password is updated into database but the authentication fails.
Please help