mysql 如何使用OTP(一次性密码)登录/注册Opencart

oprakyz7  于 4个月前  发布在  Mysql
关注(0)|答案(1)|浏览(39)

我正在构建一个Android应用程序使用opencart作为我的后端。
我想登录/注册是otp的基础上(没有密码需要以往任何时候)。我知道如何发送短信给用户和验证电话号码。我也收集用户的电子邮件和名称。
我需要了解如何注册一个没有密码的用户,然后在没有密码的情况下进行登录?

xt0899hw

xt0899hw1#

在opencart中的所有注册过程都在模型中:catalog/model/account/customer.php函数addCustomer

$this->db->query("INSERT INTO " . DB_PREFIX . "customer SET customer_group_id = '" . (int)$customer_group_id . "', store_id = '" . (int)$this->config->get('config_store_id') . "', language_id = '" . (int)$this->config->get('config_language_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? json_encode($data['custom_field']['account']) : '') . "', salt = '" . $this->db->escape($salt = token(9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = '1', approved = '" . (int)!$customer_group_info['approval'] . "', date_added = NOW()");

字符串
opencart中的所有登录过程都在library system/library/cart/customer. php函数login中

if ($override) {
        $customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND status = '1'");
    } else {
        $customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1' AND approved = '1'");
    }


Parametr $override用于通过令牌从管理面板无密码登录。令牌是一次性的,登录后会被清除。
有关此过程的一些代码位于控制器目录/帐户/login. php中

if (!empty($this->request->get['token'])) { 
.....
$customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']); // find customer by token


您可以使用一些哈希从用户设备作为密码,这种解决方案将比登录没有编码的otp密码更安全.
更新:您可以在应用程序中生成用户令牌,然后使用请求从应用程序更新opencart db:“UPDATE“. DB_PREFIX .“customer SET token = 'token_for_user' WHERE telephone = 'user_telephone”by user telephone.. OR“UPDATE“. DB_PREFIX .“customer SET token = 'token_for_user' WHERE email = 'user_email”by user_电子邮件.比GET请求http://your-site.com/index.php?route=account/login&token=generated_token.此请求后,用户会话将被创建。.电子邮件/电话号码将只需要令牌更新.登录将只生成令牌,没有任何其他数据需要,因为现在的作品从管理面板登录到客户的帐户。

相关问题