HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers64/klimroosbudel.nl/wwwroot/kms/app/models/m_pass_updater.class.php
<?php
/**
 * m_pass_updater.class.php
 * Created by Komma Mediadesign.
 * Author: mike
 * Date: 4/26/13
 */
class Pass_Updater_Model extends Model
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * gets the hash of the current password
     *
     * @param int
     * @return string / boolean
     */
    public function get($userId)
    {
        if (! empty($userId)) {
            $this->Db->setTableName('kms_admin');
            $this->Db->setData(['hash'=>'']);
            $this->Db->clearRule();
            $this->Db->addRule('id', $userId);
            $result = $this->Db->select();
            print_r($result);
            if ($result['hash']) {
                return $result['hash'];
            }
        }

        return false;
    }

    /**
     * Stores a new password in the database
     *
     * @param $new
     * @param $actHash
     * @return null
     */
    public function update($new, $actHash)
    {
        global $pdo;

        // Get admin id
        $query = 'SELECT DISTINCT adm.id
                  FROM kms_admin AS adm, kms_activation AS act
                  WHERE adm.email = act.email
                  AND act.hash = :hash
                  LIMIT 1';

        if ($st = $pdo->prepare($query)) {
            $st->bindParam(':hash', $actHash);
            if ($st->execute()) {
                $user = $st->fetchAll(PDO::FETCH_ASSOC);
                $userId = $user[key($user)]['id'];

                // prepare new hash
                $newHash = $this->prepare($new, $userId);

                $this->Db->setTableName('kms_admin');
                $this->Db->setData(['hash'=>$newHash]);
                $this->Db->addRule('id', $userId);
                $this->Db->update();

                if (! class_exists('Pass_Activation')) {
                    require_once DOCUMENT_ROOT.'app/controllers/c_pass_activation.class.php';
                }
                $act = new Pass_Activation();
                $act->update($actHash);
            }
        }

        return false;
    }

    /**
     * Encrypt Password
     *
     * @param $pass
     * @param $userId
     * @return string
     */
    private function prepare($pass, $userId)
    {
        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
            if ($currentHash = $this->get($userId)) {
                $newHash = crypt($pass, $currentHash);

                return $newHash;
            }
        } else {
            $newHash = hash('sha256', $pass);

            return $newHash;
        }

        return false;
    }
}