Skip to content

Commit

Permalink
add hashing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Aug 25, 2022
1 parent bd524ac commit bb26f82
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,42 @@


## Overview
Hashing is not yet available in Supercharge v2.
Supercharge comes with a hashing package allowing you to seamlessly hash values and verify already hashed values against their plain-text reference. Use the `Hash` facade to create hashes using the bcrypt driver. Bcrypt is a great hashing algorithm because it comes with an adjustable “work factor” (typically called “rounds”).


## 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.


## Hashing Passwords
Create a hash using the `make` method from the `Hash` facade:

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

const hash = 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:

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

if (Hash.check('plain-text', $hashValue)) {
// … 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:

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

if (Hash.needsRehash($hashValue)) {
$hashValue = await Hash.make('plain-value')
}
```
2 changes: 1 addition & 1 deletion navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
slug: 'security',
sections: {
Encryption: 'encryption',
// Hashing: 'hashing',
Hashing: 'hashing',
}
},

Expand Down

0 comments on commit bb26f82

Please sign in to comment.