Handle invalid bcrypt salt errors in Bcrypt compare (#2615)
This commit is contained in:
parent
d6f087efad
commit
6f95a2e17d
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
import { isWorkerEnvironment } from "../Utils.mjs";
|
import { isWorkerEnvironment } from "../Utils.mjs";
|
||||||
|
|
||||||
@ -43,11 +44,16 @@ class BcryptCompare extends Operation {
|
|||||||
async run(input, args) {
|
async run(input, args) {
|
||||||
const hash = args[0];
|
const hash = args[0];
|
||||||
|
|
||||||
const match = await bcrypt.compare(input, hash, undefined, p => {
|
let match;
|
||||||
// Progress callback
|
try {
|
||||||
if (isWorkerEnvironment())
|
match = await bcrypt.compare(input, hash, undefined, p => {
|
||||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
// Progress callback
|
||||||
});
|
if (isWorkerEnvironment())
|
||||||
|
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
throw new OperationError(err.toString());
|
||||||
|
}
|
||||||
|
|
||||||
return match ? "Match: " + input : "No match";
|
return match ? "Match: " + input : "No match";
|
||||||
|
|
||||||
|
|||||||
@ -993,6 +993,17 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Bcrypt compare: invalid salt version",
|
||||||
|
input: "password",
|
||||||
|
expectedOutput: "Error: Invalid salt version: $a",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Bcrypt compare",
|
||||||
|
args: ["$ab$04$K.H1WlFDQ/iIo/PiprT/puwluJ5rzuSE5q8D/Fk3NuLgU2aXiGR9m"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Scrypt: RFC test vector 1",
|
name: "Scrypt: RFC test vector 1",
|
||||||
input: "",
|
input: "",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user