From 65ac2fa7c47c3501534378db96d13f3422531349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Mon, 31 Jul 2023 14:06:38 +0200 Subject: [PATCH] add scrypt to hashing --- hashing.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hashing.md b/hashing.md index a03e57d..076486c 100644 --- a/hashing.md +++ b/hashing.md @@ -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') } ```