File: D:/HostingSpaces/SBogers59/ferrumbv.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
*
* @access public
* @param int
* @return string / boolean
*/
public function get($userId)
{
if( ! empty($userId))
{
$this->Db->setTableName('kms_admin');
$this->Db->setData(array('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
*
* @access public
* @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(array('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
*
* @access private
* @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;
}
}