Skip to content

Commit bc82577

Browse files
committed
docs: add legacy password hashing
1 parent dfcd57a commit bc82577

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/user-management/user-migration.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,29 @@ You can create a map to match the user info from your existing user profile to *
2020

2121
Logto uses [Argon2](https://en.wikipedia.org/wiki/Argon2) to hash the user's password, and also supports other algorithms like `MD5`, `SHA1`, `SHA256` and `Bcrypt` for the convenience of migration. Those algorithms are considered insecure, the corrosponding password hashes will be migrated to Argon2 upon the user's first successful sign in.
2222

23-
If you need support for any particular hashing algorithm, [please let us know](https://logto.io/contact).
23+
If you are using other hashing algorithms or salt, you can set the `passwordAlgorithm` to `Legacy`, this allows you to use any hash algorithm supported by Node.js. In this case, the `passwordDigest` will be a JSON string that contains the hash algorithm and other algorithm-specific parameters.
24+
25+
The format of the JSON string is as follows:
26+
27+
```json
28+
["hash_algorithm", ["argument1", "argument2", ...], "expected_hashed_value"]
29+
```
30+
31+
And you can use @ as the input password in the arguments.
32+
33+
For example, if you are using SHA256 with a salt, you can store the password in the following format:
34+
35+
```json
36+
["sha256", ["salt123", "@"], "c465f66c6ac481a7a17e9ed5b4e2e7e7288d892f12bf1c95c140901e9a70436e"]
37+
```
38+
39+
This equals to the following code:
40+
41+
```ts
42+
const hash = crypto.createHash('sha256');
43+
hash.update('salt123' + 'password123');
44+
const expectedHashedValue = hash.digest('hex');
45+
```
2446

2547
## Steps to migrate \{#steps-to-migrate}
2648

0 commit comments

Comments
 (0)