<commit_before><?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class User_model extends CI_model
{
	function __construct()
	{
		// call model constructor
		parent::__construct();
	}


	/**
	 * check if login credentials are correct
	 */
	function validate($lid, $pwd)
	{
		$this->db->select("uid, password, li<PASSWORD>");
		$this->db->where('liuid', $lid);
		// password query
		$pwq = $this->db->get("users");
		$pwr = $pwq->result(); // password result

		if($this->passwordhash->CheckPassword($pwd, $pwr[0]->password))
		{
			return $pwr[0];
		}
		return false;
	}


	/**
	 * check if user has given privil
	 */
	function has_privilege($id, $what)
	{
		$this->db->where('uid', $id);
		$this->db->where('privil <=', $what);
		$query = $this->db->get('admin');

		if($query->num_rows() > 0)
		{
			return $query;
		}

		return false;
	}

	/**
	 * collect privil for user
	 */
	function get_privil($id)
	{
		$this->db->select("*");
		$this->db->where('uid', $id);

		$query = $this->db->get('admin');
		$result = $query->result();

		if($query)
		{
			return $result[0]->privil;
		}

		return false;
	}

	/**
	 * get certain user info, such as name or other
	 */
	function get_info($uid, $what)
	{
		$this->db->select($what);
		$this->db->where('uid', $uid);
		$query = $this->db->get('users');

		$result = $query->result();

		if($query->num_rows() == 1)
		{
			return $result[0]->$what;
		}

		return false;
	}

	/**
	 * create a new user
	 */
	function create_user($liuid, $fname, $sname, $password, $privil = 2)
	{
		if(strlen($liuid) == 8 && !empty($fname) && !empty($fname) && strlen($password) > 6
			&& !$this->liuid_exists($liuid))
		{
			$data = array(
						'fname'		=> $fname,
						'sname'		=> $sname,
						'password'	=> $this->passwordhash->HashPassword($password),
						'liuid'		=> $liuid
					);
			return $this->db->insert('users', $data) && $this->change_privil($this->get_id($liuid), $privil);
		}
		return false;
	}

	/**
	 * set user privil
	 */
	function change_privil($uid, $privil)
	{
		$privil = $privil > 4 ? 4 : $privil;

		$this->db->select("uid");
		$this->db->where("uid", $uid);
		$query = $this->db->get("admin");

		// create privil entry in db
		if($query->num_rows() == 0)
		{
			return $this->db->insert("admin", array("uid" => $uid, "privil" => $privil));
		}
		else // update existing
		{
			return $this->db->update("admin", array("privil" => $privil), array("uid" => $uid));
		}

		return false;
	}

	function edit_user($id, $liuid, $fname, $sname, $password, $privil)
	{
		if(strlen($liuid) !== 8 || empty($fname) || empty($fname))
			return false;

		$data = array(
					'liuid' => $liuid,
					'fname' => $fname,
					'sname' => $sname
				);

		if(strlen($password) >= 6)
			$data['password'] = $this->passwordhash->HashPassword($password);

		return $this->change_privil($id, $privil) && $this->db->update('users', $data, array("uid" => $uid));
	}

	/**
	 * check if a liuid exist in the database
	 */
	function liuid_exists($liuid)
	{
		$this->db->where('liuid', $liuid);<commit_msg>typo in the where clause<commit_after><?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class User_model extends CI_model
{
	function __construct()
	{
		// call model constructor
		parent::__construct();
	}


	/**
	 * check if login credentials are correct
	 */
	function validate($lid, $pwd)
	{
		$this->db->select("uid, password, liuid");
		$this->db->where('liuid', $lid);
		// password query
		$pwq = $this->db->get("users");
		$pwr = $pwq->result(); // password result

		if($this->passwordhash->CheckPassword($pwd, $pwr[0]->password))
		{
			return $pwr[0];
		}
		return false;
	}


	/**
	 * check if user has given privil
	 */
	function has_privilege($id, $what)
	{
		$this->db->where('uid', $id);
		$this->db->where('privil <=', $what);
		$query = $this->db->get('admin');

		if($query->num_rows() > 0)
		{
			return $query;
		}

		return false;
	}

	/**
	 * collect privil for user
	 */
	function get_privil($id)
	{
		$this->db->select("*");
		$this->db->where('uid', $id);

		$query = $this->db->get('admin');
		$result = $query->result();

		if($query)
		{
			return $result[0]->privil;
		}

		return false;
	}

	/**
	 * get certain user info, such as name or other
	 */
	function get_info($uid, $what)
	{
		$this->db->select($what);
		$this->db->where('uid', $uid);
		$query = $this->db->get('users');

		$result = $query->result();

		if($query->num_rows() == 1)
		{
			return $result[0]->$what;
		}

		return false;
	}

	/**
	 * create a new user
	 */
	function create_user($liuid, $fname, $sname, $password, $privil = 2)
	{
		if(strlen($liuid) == 8 && !empty($fname) && !empty($fname) && strlen($password) > 6
			&& !$this->liuid_exists($liuid))
		{
			$data = array(
						'fname'		=> $fname,
						'sname'		=> $sname,
						'password'	=> $this->passwordhash->HashPassword($password),
						'liuid'		=> $liuid
					);
			return $this->db->insert('users', $data) && $this->change_privil($this->get_id($liuid), $privil);
		}
		return false;
	}

	/**
	 * set user privil
	 */
	function change_privil($uid, $privil)
	{
		$privil = $privil > 4 ? 4 : $privil;

		$this->db->select("uid");
		$this->db->where("uid", $uid);
		$query = $this->db->get("admin");

		// create privil entry in db
		if($query->num_rows() == 0)
		{
			return $this->db->insert("admin", array("uid" => $uid, "privil" => $privil));
		}
		else // update existing
		{
			return $this->db->update("admin", array("privil" => $privil), array("uid" => $uid));
		}

		return false;
	}

	function edit_user($id, $liuid, $fname, $sname, $password, $privil)
	{
		if(strlen($liuid) !== 8 || empty($fname) || empty($fname))
			return false;

		$data = array(
					'liuid' => $liuid,
					'fname' => $fname,
					'sname' => $sname
				);

		if(strlen($password) >= 6)
			$data['password'] = $this->passwordhash->HashPassword($password);

		return $this->change_privil($id, $privil) && $this->db->update('users', $data, array("uid" => $id));
	}

	/**
	 * check if a liuid exist in the database
	 */
	function liuid_exists($liuid)
	{
		$this->db->where('liuid', $liuid);
{'fraction_non_alphanumeric': 0.22520019611047556, 'fraction_numerical': 0.004575911096584409, 'mean_word_length': 3.3808160343593414, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 154, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1190052', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2310, 'n_words': 461}