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

问题描述 投票:4回答:1

我正在使用opencart作为后端构建Android应用程序。

我希望登录/注册基于otp(永远不需要密码)。我知道如何向用户发送短信并验证电话号码。我也在收集用户电子邮件和姓名。

我需要了解如何在没有密码的情况下注册用户,然后也可以在没有密码的情况下进行登录?

php mysql opencart opencart2.x opencart-3
1个回答
3
投票

opencart中的所有注册过程均在模型中:目录/模型/帐户/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中的所有登录过程都在库system / library / cart / customer.php中功能登录

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用于通过令牌从管理面板无密码登录。令牌是一次性的,登录后将被清除。

有关此过程的某些代码在控制器目录/controller/account/login.php中

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

您可以使用用户设备中的一些哈希作为密码,此解决方案比使用未经编码的otp密码登录更安全。您可以仅使用otp密码来验证电话号码

更新:您可以在应用程序中生成用户令牌,而不是使用请求从应用程序更新opencart db:“更新”。 DB_PREFIX。用户电话的“客户SET令牌='token_for_user',电话='user_telephone”。或“更新”。 DB_PREFIX。通过“ user_email”发送的“客户SET令牌='token_for_user',电子邮件='user_email” ...比发出GET请求http://your-site.com/index.php?route=account/login&token=generated_token ...在此请求之后将创建用户会话。.仅用于令牌更新时才需要电子邮件/电话号码...仅通过生成的令牌登录,不需要任何其他数据,如正常工作现在从管理面板登录到客户的帐户。

© www.soinside.com 2019 - 2024. All rights reserved.