google-cloud-platform - 将 PHP crypt MD5 密码导入 Googl

我正在尝试 import existing使用 PHP 的 crypt 散列密码的用户从另一个应用程序进入 Google Cloud Identity Platform具有 MD5 输出的函数。

这是在 PHP 中使用的散列密码示例:

$hashed_password = '$1$AT$JGYIRSP7xIYmg1XSoJmvB1';
$user_input = 'test123';

if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
   echo "Password verified!";
}

我尝试了各种组合来导入用户和他们的密码,但似乎没有一种组合有效。这是我正在使用的 NodeJS 导入脚本:


var admin = require('firebase-admin');

var app = admin.initializeApp({
  credential: admin.credential.applicationDefault()
});

admin
  .auth()
  .importUsers(
    [
      {
        uid: '31',
        email: 'user31@test.test',
        // Must be provided in a byte buffer.
        passwordHash: Buffer.from('$1$AT$JGYIRSP7xIYmg1XSoJmvB1'),
        // Must be provided in a byte buffer.
        passwordSalt: Buffer.from('$1$AT$'),
      },
    ],
    {
      hash: {
        algorithm: 'MD5',
        rounds: 0,
      },
    }
  )
  .then((results) => {
    console.log(results);

    results.errors.forEach((indexedError) => {
      console.log(`Error importing user ${indexedError.index}`);
    });
  })
  .catch((error) => {
    console.log('Error importing users :', error);
  });

如上所述,我已经尝试了几乎所有我能想到的哈希和密码盐的组合。我试过:

  • 不传递密码盐
  • 传递AT的密码Salt>
  • 传递 AT$ 的 passwordSalt>
  • 传递 $AT 的 passwordSalt>
  • 传递 $AT$ 的 passwordSalt>
  • 以上所有,但使用 BCRYPT 的哈希算法

我可以看到用户正在导入。如果我将散列更改为类似于常规 MD5 散列的内容,我就能够以该用户的身份进行身份验证,因此我知道导入过程工作正常。

GCP Identity Platform 是否根本不支持这些哈希值?我是否错误地传递了盐或传递了不正确的轮数?我传递了错误的哈希算法吗?我有点惊讶,因为我原以为会支持使用 PHP 的 crypt 函数散列的密码。

最佳答案

4分:

1.- 您提到您正在尝试将现有用户及其密码从另一个应用程序导入到 Google Cloud Identity Platform。此外,您提到您正在使用专注于 MD5 的 NodeJS 导入脚本。基于此,并使用您引用的相同官方 GCP 文档 Migrating users from an existing app与您发布的 NodeJS 脚本相比,您似乎没有使用该文档中发布的代码示例,完全按照它应该使用的方式使用,除非您是域“@test.test”的所有者:


    getAuth()
  .importUsers(
    [
      {
        uid: 'some-uid',
        email: 'user@example.com',
        // Must be provided in a byte buffer.
        passwordHash: Buffer.from('password-hash'),
        // Must be provided in a byte buffer.
        passwordSalt: Buffer.from('salt'),
      },
    ],
    {
      hash: {
        algorithm: 'PBKDF2_SHA256',
        rounds: 100000,
      },
    }
  )
  .then((results) => {
    results.errors.forEach((indexedError) => {
      console.log(`Error importing user ${indexedError.index}`);
    });
  })
  .catch((error) => {
    console.log('Error importing users :', error);
  });

2.- 我们确定您在 GCP 的组织中拥有 IAM 所需的管理员权限或角色吗?您可以使用以下官方 GCP 文档来了解角色 Understanding roles

3.- 你是怎么发现它不起作用的?您是否遇到以下任何错误? Error codes .导入过程完成后是否有任何特殊行为,或者您可以在此处共享编辑原始帖子的任何日志?或者仅仅是因为您看到一旦用户被导入 IAM,他们就无法进行身份验证?

4.- 我建议您现在按照此处所述(方法:users.insert)进行操作 Method: users.insert首先,您将通过这种方式查看支持的哈希格式。最后,您需要使用您在 Cloud Identity 中验证的域执行此测试。

关于google-cloud-platform - 将 PHP crypt MD5 密码导入 Google Cloud Identity Platform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69743513/

相关文章:

debugging - A/libc : Fatal signal 11 (SIGSEGV), 代码

swiftui - 如何在 iOS 15 中使用 SwiftUI 在特定 View 中隐藏 TabB

html - 在新标签页中打开 PDF - Blazor

javascript - 如何将 HTMLElement 转换为 JSX.Element

kotlin - 如何在 Kotlin Multiplatform 中获取特定于平台的换行符?

javascript - 按顺序播放多个音轨,而不是同时播放

next.js - 如何在 Next.js 中排除单个路由中的尾部斜线?

amazon-web-services - 如何查看 AWS 备份库的大小?

reactjs - 为什么我的 CSRF token 与 Laravel 和 Sanctum 不匹配

sql - 传递大的逗号分隔值时,使用 Custom TABLE TYPE 作为参数而不是 SQL