Функция входа в OpenCart

Я пытаюсь создать функцию входа в OpenCart, но происходит что-то не так, и я думаю, что это связано с получением пароля.

Tnis – это функция входа в систему:

public function login($usr, $pwd) { if ($this->user->login($usr, $pwd)) { return true; $this->doLog('logged in'); } else { $this->doLog('Failed to login, please supply a valid username/password and check your webshop url'); die; } } 

это то, как я получаю имя пользователя и пароль:

 $usr = $myAPI->cleanPost($_POST['usr']); $pwd = $myAPI->cleanPost($_POST['pwd']); 

Имя пользователя правильно, но я поставил на пароле пароль хэша.

Это все мой код:

 <?php define("VERSION", "1.0"); define("LANGUAGE", "1"); if (is_file('./../admin/config.php')) { require_once('./../admin/config.php'); } require_once(DIR_SYSTEM . 'startup.php'); $application_config = 'admin'; $registry = new Registry(); $loader = new Loader($registry); $registry->set('load', $loader); $config = new Config(); $config->load('default'); $config->load($application_config); $registry->set('config', $config); $registry->set('request', new Request()); $response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $registry->set('response', $response); $registry->set('cache', new Cache($config->get('cache_type'), $config->get('cache_expire'))); $registry->set('url', new Url($config->get('site_ssl'))); $language = new Language($config->get('language_default')); $language->load($config->get('language_default')); $registry->set('language', $language); $registry->set('document', new Document()); $event = new Event($registry); $registry->set('event', $event); if ($config->get('db_autostart')) { $registry->set('db', new DB($config->get('db_type'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'))); } if ($config->get('session_autostart')) { $session = new Session(); $session->start(); $registry->set('session', $session); } if ($config->has('action_event')) { foreach ($config->get('action_event') as $key => $value) { $event->register($key, new Action($value)); } } if ($config->has('config_autoload')) { foreach ($config->get('config_autoload') as $value) { $loader->config($value); } } if ($config->has('language_autoload')) { foreach ($config->get('language_autoload') as $value) { $loader->language($value); } } if ($config->has('library_autoload')) { foreach ($config->get('library_autoload') as $value) { $loader->library($value); } } if ($config->has('model_autoload')) { foreach ($config->get('model_autoload') as $value) { $loader->model($value); } } class K2P_API_OCWRITER extends Controller { private $errors; private $admin; private $adminValidated; private $adminShops; public function __construct($registry) { parent::__construct($registry); $this->errors = array(); } public function doLog($message) { file_put_contents('./key2_log.txt', $message, FILE_APPEND); } public function login($usr, $pwd) { if ($this->user->login($usr, $pwd)) { return true; $this->doLog('logged in'); } else { $this->doLog('Failed to login, please supply a valid username/password and check your webshop url'); die; } } function cleanPost($post) { $post = mb_convert_encoding($post, 'UTF-8', 'UTF-8'); $post = htmlentities($post, ENT_QUOTES, 'UTF-8'); return $post; $this->doLog('post: ' . print_r($post, true)); } function checkInput($usr, $pwd, $command, $page, $steps){ if ($usr === '' || $pwd === '' || $command === '') { $this->doLog("Key2Publish API OpenCart writer version" . VERSION); die; } if ((!is_numeric($page) && $page !== '') || (!is_numeric($steps) && $steps !== '')) { //echo ('Input not allowed'); die; } else{ return true; } } function getProductCount() { $this->load->model('catalog/product'); $products = $this->model_catalog_product->getProducts(); //$this->doLog(count($products)); return count($products); } public function getLanguages() { $this->load->modal('localisation/language'); $languages = $this->{'model_localisation_language'}->getLanguages(); //$this->doLog(print_r($languages, true)); $langs = ""; foreach ($languages as $language) { $lang = array(); $lang["lang_id"] = $language['language_id']; $lang["name"] = $language['name']; $langs[] = $lang; } return $langs; //$this->doLog(print_r($langs, true)); } public function getShopName() { $shops['name'] = $this->config->get('config_name'); return $shops; $this->doLog(print_r($shops, true)); } } $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); $registry->set('db', $db); $registry->set('user', new Cart\User($registry)); $registry->set('tax', new Cart\Tax($registry)); $myAPI = new K2P_API_OCWRITER($registry); $myAPI->config->set("config_language_id",LANGUAGE); $command = $myAPI->cleanPost($_POST['command']); $steps = $myAPI->cleanPost($this->request->post['steps']); $page = $myAPI->cleanPost($this->request->post['page']); $usr = $myAPI->cleanPost($_POST['usr']); $pwd = $myAPI->cleanPost($_POST['pwd']); $myAPI->doLog(print_r($_REQUEST, true)); //$myAPI->doLog('usr: ' . $usr); //$myAPI->doLog('pwd: ' . $pwd); //$myAPI->doLog(PHP_EOL . 'pages: ' . $page); //$myAPI->doLog(PHP_EOL . 'steps: ' . $steps); //$myAPI->doLog(print_r($_POST, true)); //$myAPI->doLog(var_dump($pwd)); $totalProducts = $myAPI->getProductCount(); //$myAPI->doLog(print_r($totalProducts, true)); //$myAPI->doLog(var_dump($_POST, true)); if ($myAPI->checkInput($usr,$pwd,$command,$page,$steps)) { //$myAPI->doLog(print_r($_POST, true)); //$myAPI->doLog(print_r($usr, true)); //$myAPI->doLog('pwd2 bofre login: ' . print_r($pwd, true)); if ($myAPI->login($usr, $pwd)) { //$myAPI->doLog('pwd2 after login: ' . print_r($pwd, true)); switch($command){ case "getCategoryCount": echo json_encode($myAPI->getCategoryCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES); break; case "getProductCount"; echo json_encode($myAPI->getProductCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES); break; case "getCategories": echo json_encode($myAPI->getCategories($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES)); break; case "getProducts": echo json_encode($myAPI->getProducts($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES)); break; default: echo "Invalid command!"; break; } } } ?> по <?php define("VERSION", "1.0"); define("LANGUAGE", "1"); if (is_file('./../admin/config.php')) { require_once('./../admin/config.php'); } require_once(DIR_SYSTEM . 'startup.php'); $application_config = 'admin'; $registry = new Registry(); $loader = new Loader($registry); $registry->set('load', $loader); $config = new Config(); $config->load('default'); $config->load($application_config); $registry->set('config', $config); $registry->set('request', new Request()); $response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $registry->set('response', $response); $registry->set('cache', new Cache($config->get('cache_type'), $config->get('cache_expire'))); $registry->set('url', new Url($config->get('site_ssl'))); $language = new Language($config->get('language_default')); $language->load($config->get('language_default')); $registry->set('language', $language); $registry->set('document', new Document()); $event = new Event($registry); $registry->set('event', $event); if ($config->get('db_autostart')) { $registry->set('db', new DB($config->get('db_type'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'))); } if ($config->get('session_autostart')) { $session = new Session(); $session->start(); $registry->set('session', $session); } if ($config->has('action_event')) { foreach ($config->get('action_event') as $key => $value) { $event->register($key, new Action($value)); } } if ($config->has('config_autoload')) { foreach ($config->get('config_autoload') as $value) { $loader->config($value); } } if ($config->has('language_autoload')) { foreach ($config->get('language_autoload') as $value) { $loader->language($value); } } if ($config->has('library_autoload')) { foreach ($config->get('library_autoload') as $value) { $loader->library($value); } } if ($config->has('model_autoload')) { foreach ($config->get('model_autoload') as $value) { $loader->model($value); } } class K2P_API_OCWRITER extends Controller { private $errors; private $admin; private $adminValidated; private $adminShops; public function __construct($registry) { parent::__construct($registry); $this->errors = array(); } public function doLog($message) { file_put_contents('./key2_log.txt', $message, FILE_APPEND); } public function login($usr, $pwd) { if ($this->user->login($usr, $pwd)) { return true; $this->doLog('logged in'); } else { $this->doLog('Failed to login, please supply a valid username/password and check your webshop url'); die; } } function cleanPost($post) { $post = mb_convert_encoding($post, 'UTF-8', 'UTF-8'); $post = htmlentities($post, ENT_QUOTES, 'UTF-8'); return $post; $this->doLog('post: ' . print_r($post, true)); } function checkInput($usr, $pwd, $command, $page, $steps){ if ($usr === '' || $pwd === '' || $command === '') { $this->doLog("Key2Publish API OpenCart writer version" . VERSION); die; } if ((!is_numeric($page) && $page !== '') || (!is_numeric($steps) && $steps !== '')) { //echo ('Input not allowed'); die; } else{ return true; } } function getProductCount() { $this->load->model('catalog/product'); $products = $this->model_catalog_product->getProducts(); //$this->doLog(count($products)); return count($products); } public function getLanguages() { $this->load->modal('localisation/language'); $languages = $this->{'model_localisation_language'}->getLanguages(); //$this->doLog(print_r($languages, true)); $langs = ""; foreach ($languages as $language) { $lang = array(); $lang["lang_id"] = $language['language_id']; $lang["name"] = $language['name']; $langs[] = $lang; } return $langs; //$this->doLog(print_r($langs, true)); } public function getShopName() { $shops['name'] = $this->config->get('config_name'); return $shops; $this->doLog(print_r($shops, true)); } } $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); $registry->set('db', $db); $registry->set('user', new Cart\User($registry)); $registry->set('tax', new Cart\Tax($registry)); $myAPI = new K2P_API_OCWRITER($registry); $myAPI->config->set("config_language_id",LANGUAGE); $command = $myAPI->cleanPost($_POST['command']); $steps = $myAPI->cleanPost($this->request->post['steps']); $page = $myAPI->cleanPost($this->request->post['page']); $usr = $myAPI->cleanPost($_POST['usr']); $pwd = $myAPI->cleanPost($_POST['pwd']); $myAPI->doLog(print_r($_REQUEST, true)); //$myAPI->doLog('usr: ' . $usr); //$myAPI->doLog('pwd: ' . $pwd); //$myAPI->doLog(PHP_EOL . 'pages: ' . $page); //$myAPI->doLog(PHP_EOL . 'steps: ' . $steps); //$myAPI->doLog(print_r($_POST, true)); //$myAPI->doLog(var_dump($pwd)); $totalProducts = $myAPI->getProductCount(); //$myAPI->doLog(print_r($totalProducts, true)); //$myAPI->doLog(var_dump($_POST, true)); if ($myAPI->checkInput($usr,$pwd,$command,$page,$steps)) { //$myAPI->doLog(print_r($_POST, true)); //$myAPI->doLog(print_r($usr, true)); //$myAPI->doLog('pwd2 bofre login: ' . print_r($pwd, true)); if ($myAPI->login($usr, $pwd)) { //$myAPI->doLog('pwd2 after login: ' . print_r($pwd, true)); switch($command){ case "getCategoryCount": echo json_encode($myAPI->getCategoryCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES); break; case "getProductCount"; echo json_encode($myAPI->getProductCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES); break; case "getCategories": echo json_encode($myAPI->getCategories($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES)); break; case "getProducts": echo json_encode($myAPI->getProducts($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES)); break; default: echo "Invalid command!"; break; } } } ?> 

Может ли кто-нибудь помочь мне с логином? И получить пароль правильно?

Благодаря!