<?php
class ModelUsertrocasenha extends Model {
	

	public function editPassword($user_id, $password) {
		$this->db->query("UPDATE `" . DB_PREFIX . "user` SET salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "', code = '' WHERE user_id = '" . (int)$user_id . "'");
	}

	
	public function getPassword($user_id) {
      	$query = $this->db->query("SELECT password FROM `" . DB_PREFIX . "user` WHERE user_id = '" . (int)$user_id . "'");
		
		return $query->row['password'];
	}
        
        
        public function verifyPassword($password){
            
            $user_query = $this->db->query("SELECT * FROM `" . DB_PREFIX ."user` WHERE `password` = SHA1(CONCAT(`salt`, SHA1(CONCAT(`salt`, SHA1('" . $this->db->escape($password) ."'))))) OR `password` = '" . $this->db->escape(md5($password))."'");

    	if ($user_query->num_rows) {
			return true;
            
        }else{
            
            return false; 
         }
     }
}
