# Can't log in using imported pbkdf2 hashed passwords

**URL:** <https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815>\
**Category:** Get Help\
**Tags:** bulk-user-import, import-password\
**Created:** [April 27, 2021, 9:35am UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815 "2021-04-27T09:35:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan.unger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alan.unger/32/13075_2.png) [@alan.unger](https://community.auth0.com/u/alan.unger)\
**Post date:** [April 27, 2021, 9:35am UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/1 "2021-04-27T09:35:33Z")

</div>

Hi!

I’m trying to use a user imported into Auth0, using passwords with hash pbkdf2, the job runs successfully, but I can’t log in using the user imported.

Original values:

Hash (hex) = b32252fcd4ec70df9d951bfea92bd0da39cc360b1a4821eb5af01fea6c1857075ea216b74c03bf68f1149849c358450ccb4575071b53d158c03954174c3ab18e

Salt = 50e04e8c45254453dc098782fb51543e

file.json

```
[   
    {
        "email": "fakeemail@gmail.com",
        "email_verified": true,
        "name": "Test user",
        "custom_password_hash": {
           "algorithm": "pbkdf2",
            "hash": {
                 "value":"$pbkdf2-sha512$i=1000,l=64$NTBlMDRlOGM0NTI1NDQ1M2RjMDk4NzgyZmI1MTU0M2U$YjMyMjUyZmNkNGVjNzBkZjlkOTUxYmZlYTkyYmQwZGEzOWNjMzYwYjFhNDgyMWViNWFmMDFmZWE2YzE4NTcwNzVlYTIxNmI3NGMwM2JmNjhmMTE0OTg0OWMzNTg0NTBjY2I0NTc1MDcxYjUzZDE1OGMwMzk1NDE3NGMzYWIxOGU",
                "encoding": "utf8"
            }
        }
    }

]

```

error Message

```
{
  "error": {
    "message": "Password change required.",
    "reason": "Verification failed for the provided custom_password_hash: {'algorithm':'pbkdf2','hash':{'value':'$pbkdf2-sha512$i=1000,l=64$UOBOjEU...','encoding':'utf8'},'salt':{'value':''}}"
  }
}

```

What am I doing wrong?

`S

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 27, 2021, 11:05pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/3 "2021-04-27T23:05:17Z")

</div>

Did you follow the PHC format for `hash.value` mentioned in the [pbkdf2 hash import doc](https://auth0.com/docs/users/bulk-user-import-database-schema-and-examples#pbkdf2)?

Here is the link from that doc that describes it:

> <https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md>

---

<div class="post-metadata">

**Author:** ![alan.unger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alan.unger/32/13075_2.png) [@alan.unger](https://community.auth0.com/u/alan.unger)\
**Post date:** [April 28, 2021, 1:25pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/4 "2021-04-28T13:25:00Z")

</div>

Yes, i’m using this example:

> **[Bulk User Import Database Schema and Examples](https://auth0.com/docs/manage-users/user-migration/bulk-user-import-database-schema-and-examples)**
>
> Learn how to perform bulk user imports with the Management API.

```
{
        "email": "cecil@contoso.com",
        "email_verified": false,
        "custom_password_hash": {
            "algorithm": "pbkdf2",
            "hash": {
                "value": "$pbkdf2-sha512$i=100000,l=64$KNyFsA2rWoE$I2CQGI9H0JxdDf3kERRI97kPCGxh0KWBIV3MxyaS191gDGfzVBGyS4BibhgqWQ0/ails8mHuU9ckASxHOOq58w"
            }
        }
    }

```

And this lib to generate the string

> **[@phc/format](https://www.npmjs.com/package/@phc/format)**
>
> PHC string format serializer/deserializer. Latest version: 1.0.0, last published: 3 years ago. Start using @phc/format in your project by running \`npm i @phc/format\`. There are 20 other projects in the npm registry using @phc/format.

But, no success =/

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 28, 2021, 3:44pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/5 "2021-04-28T15:44:22Z")

</div>

Can you post the code you are using to create the `hash.value`? I’d like to try it and see if I can get it working.

---

<div class="post-metadata">

**Author:** ![alan.unger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alan.unger/32/13075_2.png) [@alan.unger](https://community.auth0.com/u/alan.unger)\
**Post date:** [April 29, 2021, 10:53am UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/6 "2021-04-29T10:53:44Z")

</div>

=)

This is the code to generate hash.value to use in Auth0 process:

```
const phc = require("@phc/format");

const exportUsers = (users) => {
  users.map((user) => {
    const value = phc.serialize({
      id: "pbkdf2-sha512",
      params: { i: 1000, l: 64 },
      salt: Buffer.from(user.salt),
      hash: Buffer.from(user.password)
    });
    
    console.log(value);
  });
};

```

to hash the passwords with pbkdf2 :

```
import crypto from "crypto";
import _ from "lodash";

export async function hashPassword(password, salt) {
  return crypto.pbkdf2Sync(password, salt, 1000, 64, "sha512").toString("hex");
} 

export async function getHashedCredential(credential) {
  const newCredential = credential;

  if (_.hasIn(credential, "password")) {
    const salt = crypto.randomBytes(16).toString("hex");
    const hash = await hashPassword(credential.password, salt);
    newCredential.password = hash;
    newCredential.salt = salt;
  }

  return newCredential;
}

```

tks

---

<div class="post-metadata">

**Author:** ![alan.unger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alan.unger/32/13075_2.png) [@alan.unger](https://community.auth0.com/u/alan.unger)\
**Post date:** [May 7, 2021, 11:25am UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/7 "2021-05-07T11:25:40Z")

</div>

Hi Dan, any news about the code?

s

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 7, 2021, 6:13pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/8 "2021-05-07T18:13:40Z")

</div>

I spent a bit of time on this and couldn’t get it to work either. These hash imports are fairly delicate because of the range of params that can be manipulated.

A couple of things I noticed:

- Your example import has an `i` of 100000, although it looks like you are using 1000 in your hashPassword function. I don’t think this would happen if you used the exportUsers function you provided, but it’s worth noting, I’m not sure how you could’ve come to that example.

```auto
"value": "$pbkdf2-sha512$i=100000,l=64$KNyFsA2rWoE$I2CQGI9H0JxdDf3kERRI97kPCGxh0KWBIV3MxyaS191gDGfzVBGyS4BibhgqWQ0/ails8mHuU9ckASxHOOq58w"

```

- The import requires `“encoding”: “utf8”` (this should default, so it may not be an issue.)
- In your exportUsers script you are using

```auto
hash: Buffer.from(user.password)

```

Which has a default encoding of utf8. I think you would want to pass

```auto
Buffer.from(user.password, 'hex')

```

All this said, I tried to make these changes and couldn’t get it to accept the password. I suspect there is an encoding issue somewhere, but can’t seem to figure it out.

---

<div class="post-metadata">

**Author:** ![alan.unger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alan.unger/32/13075_2.png) [@alan.unger](https://community.auth0.com/u/alan.unger)\
**Post date:** [May 8, 2021, 3:32am UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/9 "2021-05-08T03:32:37Z")

</div>

I noticed these things to, I changed it on my code from 10000 to 1000, just forgot to replace here, sorry.

I tried to use “hex” parameter in my first attempt, but no effect so I just removed it to test the parameters values and forgot it too =/

Thanks, I’m still trying to make it work.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 11, 2021, 3:49pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/10 "2021-05-11T15:49:19Z")

</div>

Let us know if you have any success!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 1, 2021, 5:08pm UTC](https://community.auth0.com/t/cant-log-in-using-imported-pbkdf2-hashed-passwords/61815/11 "2021-06-01T17:08:12Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
