获取用户名和密码OpenCart

时间:2017-04-15 12:08:01

标签: php login passwords opencart username

我想检查用户是否已登录。我想检查用户名和密码。有谁有想法吗?我正在进行登录功能,我想检查用户名和密码。对于PrestaShop,我这样做了:

if (empty($email)) {
        $this->errors[] = Tools::displayError('Email is empty.');
        $this->doLog('ERROR: Email/username is empty');
    } elseif (!Validate::isEmail($email)) {
        $this->errors[] = Tools::displayError('Invalid email address.');
        $this->doLog('ERROR: Invalid Email address');
    }

    if (empty($pwd)) {
        $this->errors[] = Tools::displayError('The password field is blank.');
        $this->doLog('ERROR: The password field is blank');
    } elseif (!Validate::isPasswd($pwd)) {
        $this->errors[] = Tools::displayError('Invalid password.');
        $this->doLog('ERROR: Invalid password');
    }

有谁知道如何获取用户名和密码?我怎么能检查他们是否被填写?以及我如何验证它们?

由于

1 个答案:

答案 0 :(得分:0)

如果您想检查客户是否已登录,则可以这样检查

$this->customer->isLogged() // for customer

要检查管理员用户,请尝试此操作

$this->user->isLogged() // for admin users

要获取用户名,请尝试此操作

$this->user->getUsername() // for admin users
$this->customer->getUsername() // for customers

对于密码,您需要修改system / library / cart / user.php

class User {
 ...
 private $password;
 ...

public function __construct($registry) {
 ...
 ...
 $this->username = $user_query->row['username'];
 $this->password = $user_query->row['password'];
 $this->user_group_id = $user_query->row['user_group_id'];
 ...
 ...
}

public function login($username, $password) {
 ...
 ...
 $this->username = $user_query->row['username'];
 $this->password = $user_query->row['password'];
 $this->user_group_id = $user_query->row['user_group_id'];
 ...
 ...
}

// add a new method to get password
public function getPassword() {
 return $this->password;
}

现在请拨打$ this-> user-> getPassword()来获取密码。这适用于管理员用户。如果您想获得客户的密码,请以同样的方式更新文件{{1}。