实现用户在挂钩菜单中有密码

2022-01-23 00:00:00 php drupal-7

我们正在为 Drupal 7 站点实施 Web 服务(Web 服务代码不是 drupal 安装文件夹的一部分).

we are implementing a web service for a Drupal 7 site (the web service code is not part of drupal installation folder).

其中一项网络服务需要在网站上注册用户.主要障碍是获得 Drupal 也能识别的散列密码.

one of the web services needs to sign up the user on the site. the main hurdle was getting a hashed password that Drupal will also recognize.

为此,我遵循关于堆栈溢出的建议,以在 drupal 内实现 REST 服务并从外部服务代码调用该服务.(这部分似乎也是可能和可实现的).

for that , am following a suggestion made on stack overflow to Implement a REST service inside drupal and call that from the outside service code . (that part also seems possible and achieveable).

已经使用以下代码实现了密码哈希服务:

have implemented a password hashing service with following code:

function GetHashedPassword($string)
{
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');

    $hashedpw = user_hash_password($string);

    $data = array(
        'password' => $hashedpw
    );

    header("Access-Control-Allow-Origin: *");

    drupal_json_output($data);
    drupal_exit();
}

现在的主要问题是,即使使用相同的字符串调用此服务,它每次都会返回一个新的哈希值..

the main issue now is that whenever this service is called even with same string , it returns a new hashed value each time..

如果我们需要的东西实际上是可能的,请提供帮助,如果是的话,那么可以在上面的代码中修复什么

kindly assist if what we need is actually even possible and if so, then what could be fixed in the above code

任何帮助表示赞赏

推荐答案

Drupal user_hash_password 函数每次计算哈希时都会生成一个新的盐.这将导致生成新的哈希,因为盐可能与上一个不同.

The Drupal user_hash_password function generates a new salt each time it calculates the hash. This will cause a new hash to be generated since the salt is likely to be different to the last one.

相关文章