bcrypt = new \Bcrypt(15); $this->db =& \miniMVC\db::get_instance(); $this->session =& \miniMVC\Session::get_instance(); } // -------------------------------------------------------------------------- /** * Add a user for access * * @param string * @param string * @param string */ public function add_user($username, $pass1, $pass2) { // Check for the existing username $query = $this->db->select('username') ->from('user') ->where('username', $username) ->get(); $res = $query->fetch(\PDO::FETCH_ASSOC); if (empty($res)) return FALSE; // Verify that passwords match if ($pass1 !== $pass2) return FALSE; // Add user $hashed = $this->bcrypt->hash($pass1); $this->db->set('username', $username) ->set('hash', $hashed) ->insert('user'); return TRUE; } // -------------------------------------------------------------------------- /** * Check and see if the login is valid * * @param string * @param string * @return bool */ public function check_login($username, $pass) { $query = $this->db->from('user') ->where('username', $username) ->get(); $row = $query->fetch(\PDO::FETCH_ASSOC); // The user does not exist if (empty($row)) { return FALSE; } return $this->bcrypt->verify($pass, $row['hash']); } } // End of user_model.php