如何从laradoo包中的res.users模型验证用户

问题描述

我已经在我的 laradoo 项目中安装了 Laravel 包,它将连接到 odoo DB。我已连接到数据库,但现在我无法从 res.users model用户进行身份验证。因为当我尝试使用以下代码获取用户信息时。

$odoo = new \Edujugon\Laradoo\odoo();
$odoo = $odoo->connect();
$models = $odoo->where('login','test@test.com')->fields('name','login','password')->get('res.users');
echo "<pre>";
print_r($models);

在不返回密码的情况下,它给出了以下响应。

Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [0] => Array
                (
                    [id] => 6
                    [name] => test
                    [login] => test@test.com
                    [password] => 
                )
         )
)

所以,我尝试了另一种方式,例如在 Laravel 上创建哈希并尝试像下面的代码一样进行身份验证

$odoo = new \Edujugon\Laradoo\odoo();

$odoo = $odoo->connect();
$password = "12345";
$iterations = 1000;

// Generate a random IV using openssl_random_pseudo_bytes()
// random_bytes() or another suitable source of randomness
$salt = openssl_random_pseudo_bytes(16);

$hash = hash_pbkdf2("sha512",$password,$salt,$iterations,20);

$models = $odoo->where('login','test@test.com')->where('password',$hash)->fields('name','password')->get('res.users');

echo "<pre>";
print_r($models);

但它无法正常工作。如果密码正确错误,它将始终返回给用户。因此,如果您能帮助我从 odoo 中获取密码或为 odoo res.users model 创建哈希,那就太好了。

解决方法

如果您需要覆盖 laravel 哈希以接受来自 odoo DB 的密码。您需要根据您在 EloquentUserProvider.php 中的散列需要修改以下函数

public function validateCredentials(UserContract $user,array $credentials)
    {
        $plain = $credentials['password'];

        $hash = hash('sha512',$plain);
        if($hash == $user->getAuthPassword() ){
            return true;

        }else{
            return false;
        }
    
        // return $this->hasher->check($plain,$user->getAuthPassword());
    }