<?php
class UserModel extends MY_Model {
	protected $table = 'users';
	protected $primary = 'id';
	protected $field_order = 'id';
	protected $type_order = 'desc';

	public function validate (string $username, string $password) {
		$username = antiInjection($username, true);
		$password = antiInjection($password, true);

		$user = $this->getRowWhere(['username' => $username]);
		if (!$user) {
			return false;
		}

		$passwordIsValid = compareHash($password, $user->password);
		if ($passwordIsValid) {
			return $user;
		}

		return false;
	}
}
