Skip to content

Commit

Permalink
add scrypt to hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jul 31, 2023
1 parent dc98427 commit 65ac2fa
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,47 @@ Supercharge comes with a hashing package allowing you to seamlessly hash values


## Configuration
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.
The hashing configuration file is located at `config/hashing.ts`. It contains the default hash driver and the corresponding hash driver settings.


### Available Hashing Drivers
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:

| Hash Driver | Description |
|-------------- |--------------------------------------------- |
| `bcrypt` | Uses the bcrypt hashing algorithm |
| `scrypt` | Uses Node.js native [scrypt](https://nodejs.org/docs/latest-v18.x/api/crypto.html#cryptoscryptpassword-salt-keylen-options-callback) hashing algorithm |


## Hashing Passwords
Create a hash using the `make` method from the `Hash` facade:
Create a hash of a given string value using the `make` method from the `Hash` facade:

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

const hash = Hash.make('plain-text')
const hashedValue = Hash.make('plain-text')
```


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

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

if (Hash.check('plain-text', $hashValue)) {
if (Hash.check('plain-text', hashedValue)) {
// … verified: values match
}
```


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

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

if (Hash.needsRehash($hashValue)) {
$hashValue = await Hash.make('plain-value')
if (Hash.needsRehash(hashedValue)) {
const newHashedValue = await Hash.make('plain-value')
}
```

0 comments on commit 65ac2fa

Please sign in to comment.