将密码PHP更改为Joomla

Hi I am currently using a PHP application which i access through a joomla site through an iframe.

The idea is to get this working with single sign on, which words just fine.

This is the code I have that takes the users password from my own php application and then encodes it to joomla hash

//encrypt password for joomla format
$salt = "";
if ($values["password"])
{
    $password = $values["password"];
    for ($i=0; $i<=32; $i++) 
        {
            $d=rand(1,30)%2;
            $salt .= $d ? chr(rand(65,90)) : chr(rand(48,57));
        } 
    $hashed = md5($password . $salt); $encrypted = $hashed . ':' . $salt;

Again this code works just fine, and I later pass it into an insert query.

The problem I am having is when I try to change the password of logged in user from my iframe application, I cant get it to update the joomla user table.

The variables available to me in this particular process are $oldpassword and $newpassword.

Could someone please help me get this working