Skip to content

Commit c320cdc

Browse files
committed
Add Argon2 hash compare operation
1 parent 8a0c751 commit c320cdc

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/core/config/Categories.json

100755100644
+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
"Bcrypt parse",
322322
"Scrypt",
323323
"Argon2",
324+
"Argon2 compare",
324325
"Fletcher-8 Checksum",
325326
"Fletcher-16 Checksum",
326327
"Fletcher-32 Checksum",

src/core/operations/Argon2Compare.mjs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @author Tan Zhen Yong [[email protected]]
3+
* @copyright Crown Copyright 2019
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import argon2 from "argon2-browser";
9+
10+
/**
11+
* Argon2 compare operation
12+
*/
13+
class Argon2Compare extends Operation {
14+
15+
/**
16+
* Argon2Compare constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "Argon2 compare";
22+
this.module = "Crypto";
23+
this.description = "Tests whether the input matches the given Argon2 hash. To test multiple possible passwords, use the 'Fork' operation.";
24+
this.infoURL = "https://wikipedia.org/wiki/Argon2";
25+
this.inputType = "string";
26+
this.outputType = "string";
27+
this.args = [
28+
{
29+
"name": "Hash",
30+
"type": "string",
31+
"value": ""
32+
}
33+
];
34+
}
35+
36+
/**
37+
* @param {string} input
38+
* @param {Object[]} args
39+
* @returns {string}
40+
*/
41+
run(input, args) {
42+
const encoded = args[0];
43+
44+
return argon2.verify({
45+
pass: input,
46+
encoded
47+
}).then(_ => {
48+
return `Match: ${input}`;
49+
}).catch(_ => {
50+
return "No match";
51+
});
52+
}
53+
54+
}
55+
56+
export default Argon2Compare;

tests/node/tests/operations.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ Tiger-128`;
138138
assert.strictEqual(result.toString(), "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw");
139139
}),
140140

141+
it("Argon2 compare", async () => {
142+
const result = await chef.Argon2Compare("argon2password", {
143+
hash: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
144+
});
145+
assert.strictEqual(result.toString(), "Match: argon2password");
146+
}),
147+
141148
it("Bcrypt", async () => {
142149
const result = await chef.bcrypt("Put a Sock In It");
143150
const strResult = result.toString();

0 commit comments

Comments
 (0)