简体   繁体   中英

get username and password OpenCart

I want to check if the user is logged in. I want to check the username and the password. Does anyone have any idea? I am making a login function and i want to check the username and the password. For PrestaShop i did it like this:

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');
    }

Does anyone know how to get the username and the password? And how i can check if they are filled in? And how i can validate them?

Thanks

If you want to check a customer is logged in or not, then you can check this way

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

And to check for admin user, try this

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

To get username, try this

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

And for password, you need to modify 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;
}

Now call $this->user->getPassword() to get password. This is for admin users. If you want to get customer's password, update the file system/library/cart/customer.php same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM