-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add pepper support to argon2 hashing #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d829512
feat: add pepper support to argon2 hashing
Absy00 633efc7
test: move pepper tests to argon2 directory per PR feedback
Absy00 cc3ce2f
test: remove redundant distinctness test case per Bugbot feedback
Absy00 43fa686
chore: resolve merge conflict in CHANGELOG.md
Absy00 792d713
chore: merge main into feat/argon2-pepper
Absy00 6a5daff
feat(argon2): add pepper length validation and restrict type to string
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { createArgon2Hashing } from "./argon2.ts"; | ||
| import assert from "node:assert/strict"; | ||
| import { describe, it } from "node:test"; | ||
|
|
||
| void describe("Argon2 Pepper Support", () => { | ||
| const password = "my-secret-password"; | ||
| const firstPepper = "secret-pepper-one"; | ||
| const secondPepper = "secret-pepper-two"; | ||
|
|
||
| void it("should successfully verify a password when the correct pepper is provided", async () => { | ||
| const hashing = createArgon2Hashing({ pepper: firstPepper }); | ||
| const hash = await hashing.hash(password); | ||
|
|
||
| const isValid = await hashing.verify(password, hash); | ||
| assert.strictEqual( | ||
| isValid, | ||
| true, | ||
| "Verification with the correct pepper should succeed", | ||
| ); | ||
| }); | ||
|
|
||
| void it("should fail verification if a different pepper is used", async () => { | ||
| const hashingA = createArgon2Hashing({ pepper: firstPepper }); | ||
| const hashingB = createArgon2Hashing({ pepper: secondPepper }); | ||
| const hash = await hashingA.hash(password); | ||
| const isValid = await hashingB.verify(password, hash); | ||
|
|
||
| assert.strictEqual( | ||
| isValid, | ||
| false, | ||
| "Verification with a mismatched pepper should fail", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| void describe("Argon2 Pepper Validation", () => { | ||
| const minIncludedPepper = "a"; | ||
| const minExcludedPepper = ""; | ||
|
|
||
| const maxIncludedPepper = "a".repeat(1024); | ||
| const maxExcludedPepper = "a".repeat(1025); | ||
|
|
||
| for (const pepper of [minIncludedPepper, maxIncludedPepper]) { | ||
| const password = "my-secret-password"; | ||
|
|
||
| void it(`should verify a password when the pepper is ${pepper.length} characters long`, async () => { | ||
| const hashing = createArgon2Hashing({ pepper }); | ||
| const hash = await hashing.hash(password); | ||
|
|
||
| const isValid = await hashing.verify(password, hash); | ||
| assert.strictEqual( | ||
| isValid, | ||
| true, | ||
| "Verification with the correct pepper should succeed", | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| for (const pepper of [minExcludedPepper, maxExcludedPepper]) { | ||
| void it(`should throw an error if the pepper is ${pepper.length} characters long`, () => { | ||
| assert.throws(() => { | ||
| createArgon2Hashing({ pepper }); | ||
| }, "Expected error to be thrown"); | ||
| }); | ||
| } | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.