<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH.'modules/generic/controllers/Generic.php';

class Security extends Generic{
	function __construct() {
		parent::__construct();
	}
	
	/*
	**	CREATE HASH 
	*/
	function makeHash($password){
		$options = array(
			'cost' => 12
		);
		
		$hash = password_hash($password, PASSWORD_BCRYPT, $options);
		echo $hash;
	}

	/*
	**	VERIFY PASSWORD
	*/
	function verifyPassoword($password, $hash){
		if(password_verify($password, $hash)){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	/*
	**	VERIFY ADMIN SESSION
	*/
	function isAdmin(){
		if($this->session->userdata('admin')){
			
			$user = $this->session->userdata('admin');
			if(is_numeric($user['id']) && $user['type']=="admin"){
				return TRUE;
			}else{
				return FALSE;
			}
		}else{
			return FALSE;
		}
	}

	/*
	**	VERIFY MEMBER SESSION
	*/
	function isMember(){
		if($this->session->userdata('user')){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	/*
	**	USE OF PASSWORD HASH METHOD
	*/
	function test(){
		$options = array(
			'cost' => 12
		);
		
		$password = 'plex@admin';
		echo $hash = password_hash($password, PASSWORD_BCRYPT, $options);
		echo '<br>';

		if(password_verify($password, $hash)){
			echo 'TRUE';
		} else {
			echo 'FALSE';
		}
	}
}