-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,58 @@ | ||
/** | ||
* @author Tan Zhen Yong [tzy@beyondthesprawl.com] | ||
* @copyright Crown Copyright 2019 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import argon2 from "argon2-browser"; | ||
|
||
/** | ||
* Argon2 compare operation | ||
*/ | ||
class Argon2Compare extends Operation { | ||
|
||
/** | ||
* Argon2Compare constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Argon2 compare"; | ||
this.module = "Crypto"; | ||
this.description = "Tests whether the input matches the given Argon2 hash. To test multiple possible passwords, use the 'Fork' operation."; | ||
this.infoURL = "https://wikipedia.org/wiki/Argon2"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
"name": "Hash", | ||
"type": "string", | ||
"value": "" | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
async run(input, args) { | ||
const encoded = args[0]; | ||
|
||
try { | ||
await argon2.verify({ | ||
pass: input, | ||
encoded | ||
}); | ||
|
||
return `Match: ${input}`; | ||
} catch (err) { | ||
return "No match"; | ||
} | ||
} | ||
|
||
} | ||
|
||
export default Argon2Compare; |
This file contains 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