Skip to content

Commit 65ac2fa

Browse files
committed
add scrypt to hashing
1 parent dc98427 commit 65ac2fa

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

hashing.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,47 @@ Supercharge comes with a hashing package allowing you to seamlessly hash values
66

77

88
## Configuration
9-
The hashing configuration file is located at `config/hashing.ts`. It contains the default hash driver and the corresponding settings. At this point, only bcrypt is supported as a hash driver. You may adjust bcrypt’s work factor in the configuration file.
9+
The hashing configuration file is located at `config/hashing.ts`. It contains the default hash driver and the corresponding hash driver settings.
10+
11+
12+
### Available Hashing Drivers
13+
Supercharge uses a driver-based approach for hashing. A driver represents a hash algorithm used to generate the hash for a given value. Here’s a list of available hash drivers:
14+
15+
| Hash Driver | Description |
16+
|-------------- |--------------------------------------------- |
17+
| `bcrypt` | Uses the bcrypt hashing algorithm |
18+
| `scrypt` | Uses Node.js native [scrypt](https://nodejs.org/docs/latest-v18.x/api/crypto.html#cryptoscryptpassword-salt-keylen-options-callback) hashing algorithm |
1019

1120

1221
## Hashing Passwords
13-
Create a hash using the `make` method from the `Hash` facade:
22+
Create a hash of a given string value using the `make` method from the `Hash` facade:
1423

1524
```ts
1625
import { Hash } from '@supercharge/facades'
1726

18-
const hash = Hash.make('plain-text')
27+
const hashedValue = Hash.make('plain-text')
1928
```
2029

2130

2231
## Verifying Passwords Matching a Hash
23-
Use the `check` method from the `Hash` facade to verify that a given plain text value matches the related hash:
32+
Use the `check` method from the `Hash` facade to verify that a given plain text value matches given related hash:
2433

2534
```ts
2635
import { Hash } from '@supercharge/facades'
2736

28-
if (Hash.check('plain-text', $hashValue)) {
37+
if (Hash.check('plain-text', hashedValue)) {
2938
// … verified: values match
3039
}
3140
```
3241

3342

3443
## Determine if Rehash is Needed
35-
Use the `needsRehash` method to determine whether the work factor has changed since hashing the given value:
44+
Use the `needsRehash` method to determine whether the algorithm or hashing options have changed since creating the hashed value:
3645

3746
```ts
3847
import { Hash } from '@supercharge/facades'
3948

40-
if (Hash.needsRehash($hashValue)) {
41-
$hashValue = await Hash.make('plain-value')
49+
if (Hash.needsRehash(hashedValue)) {
50+
const newHashedValue = await Hash.make('plain-value')
4251
}
4352
```

0 commit comments

Comments
 (0)