如何使用php代码使用管理员帐户更改用户密码

has the title says. I'm right now stuck at a certain point in my code. I odn't know how to proceed.

When I use $user to the update method it works perfectly, but when I try to use $targetuser, nothing happens and I get a blank page.

Excuse the Swedish in the document, I hope you may be able to discover what I'm doing wrong anyway. Thanks in advance.

Changepass code and User class code may be found below:

changepass:

<meta charset="utf-8">
<?php
require_once 'core/init.php';

$username = Input::get('user');

$user = new User();
$targetuser = new User($username);

if (!$username) {
    Redirect::to(404);
} else {
    if (!$targetuser->exists()) {
        Redirect::to(404);
    } else {
        $data = $targetuser->data();
    }
}

?>
<!DOCTYPE html>
<!-- Template by html.am -->
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Ändra Lösenord - Menoxia</title>
        <link rel="stylesheet" href="styles/style.css" />
    </head>
    <?php
        // Denna kod är superviktig om du vill ha sidan lösenordsskyddad!
        if (!$user->isLoggedIn()) {
            Redirect::to('includes/login_required.php');
        } else {
        //slut på koden
    ?>  
    <body>
        <?php include('includes/header.php'); ?>

        <div id="wrapper">

            <main>
      <div id="content">
        <div class="innertube">
            <center>
            <br>
            <?php
                if (Input::exists()) {
                    if (Token::check(Input::get('token'))) {

                        $validate = new Validate();
                        $validation = $validate->check($_POST, array(
                            'password_current' => array(
                                'required' => true,
                                'min' => 6
                            ),
                            'password_new' => array(
                                'required' => true,
                                'min' => 6,
                                'max' => 25
                            ),
                            'password_new_again' => array(
                                'required' => true,
                                'min' => 6,
                                'max' => 25,
                                'matches' => 'password_new'
                            )
                        ));

                        if ($validation->passed()) {
                            if ($username = $user || $username = $targetuser) {
                                // Detta är till kontot som INTE är det inloggade kontot.
                                if(Input::get('password_current') === Input::get('password_new')) {
                                    echo 'Du kan inte uppdatera till samma lösenord.';
                                } else {
                                    if (Hash::make(Input::get('password_current'), $targetuser->data()->salt) !== $targetuser->data()->password) {
                                        echo 'Ditt nuvarande lösenord är fel.';
                                        echo 'MAMMA MIA!';
                                    } else {
                                        $salt = Hash::salt(32);
                                        echo $username;

                                        $targetuser->update(array(
                                            'password' => Hash::make(Input::get('password_new'), $salt),
                                            'salt' => $salt
                                        ));
/*
                                        Session::flash('home', 'Ditt lösenord har ändrats!');
                                        Redirect::to('profile.php');*/
                                    }
                                }
                            } else {
                                echo 'Något gick fel...';
                            }
                        } else {
                            foreach($validation->errors() as $error) {
                                echo $error, '<br>';
                            }
                        }
                    }
                }
            ?>
            <p><br></p>
            <br>
            <form action="" method="post">
                <div class="field">
                    <label for="password_current">Nuvarande lösenord:</label>
                    <input type="password" name="password_current" id="password_current">
                </div>

                <div class="field">
                    <label for="password_new">Nytt lösenord:</label>
                    <input type="password" name="password_new" id="password_new">
                </div>

                <div class="field">
                    <label for="password_new_again">Repetera:</label>
                    <input type="password" name="password_new_again" id="password_new_again">
                </div>
                <?php echo 'Detta kontot kan ändra lösenord: ', $user->data()->username;
                    echo ', medan detta konto ska ändras: ', $targetuser->data()->username; ?>
                <input type="submit" value="Byt Lösenord">
                <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
            </form>
            </center>
        </div>
      </div>
    </main>
    <?php include('includes/empty_menu_links.php'); ?>
</div>

<?php include('includes/footer.php'); ?>
<?php
// Varje lösenordsskyddad sida MÅSTE avslutas med denna kod!
}
?>

user:

<?php
class User {
    private $_db,
            $_data,
            $_sessionName,
            $_cookieName,
            $_isLoggedIn;

    public function __construct($user = null) {
        $this->_db = DB::getInstance();

        $this->_sessionName = Config::get('session/session_name');
        $this->_cookieName = Config::get('remember/cookie_name');

        if (!$user) {
            if (Session::exists($this->_sessionName)) {
                $user = Session::get($this->_sessionName);

                if ($this->find($user)) {
                    $this->_isLoggedIn = true;
                } else {
                    $this->_isLoggedIn = false;
                }
            }
        } else {
            $this->find($user);
        }

    }

    public function update($fields = array(), $id = null) {

        if (!$id && $this->isLoggedIn()) {
            $id = $this->data()->id;
        }

        if (!$this->_db->update('users', $id, $fields)) {
            throw new Exception('There was a problem updating.');
        }
    }

    public function create($fields = array()) {
        if (!$this->_db->insert('users', $fields)) {
            throw new Exception('There was a problem creating an account.');
        }
    }

    public function find($user = null) {
        if ($user) {
            $field = (is_numeric($user)) ? 'id' : 'username';
            $data = $this->_db->get('users', array($field, '=', $user));

            if ($data->count()) {
                $this->_data = $data->first();
                return true;
            }
        }
        return false;
    }

    public function login($username = null, $password = null, $remember = false) {

        if (!$username && !$password && $this->exists()) {
            Session::put($this->_sessionName, $this->data()->id);
        } else {
            $user = $this->find($username);

            if ($user) {
                if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
                    Session::put($this->_sessionName, $this->data()->id);

                    if ($remember) {
                        $hash = Hash::unique();
                        $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id));

                        if (!$hashCheck->count()) {
                            $this->_db->insert('users_session', array(
                                'user_id' => $this->data()->id,
                                'hash' => $hash
                            ));
                        } else {
                            $hash = $hashCheck->first()->hash;
                        }

                        Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));

                    }

                    return true;
                }
            }
        }

        return false;
    }

    public function hasPermission($key) {
        $group = $this->_db->get('groups', array('id', '=', $this->data()->group));
        if ($group->count()) {
            $permissions = json_decode($group->first()->permissions, true);

            if ($permissions[$key] == true) {
                return true;
            }

        }
        return false;
    }

    public function exists() {
        return (!empty($this->_data)) ? true : false;
    }

    public function logout() {

        $this->_db->delete('users_session', array('user_id', '=', $this->data()->id));

        Session::delete($this->_sessionName);
        Cookie::delete($this->_cookieName);
    }

    public function data() {
        return $this->_data;
    }

    public function isLoggedIn() {
        return $this->_isLoggedIn;
    }
}

Thank you in advance.

Best regards, Adam

P.S. Sorry for my bad English, I'm not a native speaking English person :)