Handle invalid bcrypt salt errors in Bcrypt compare (#2615)

This commit is contained in:
Zain Nadeem
2026-07-03 08:52:04 +00:00
committed by GitHub
parent d6f087efad
commit 6f95a2e17d
2 changed files with 22 additions and 5 deletions
+11 -5
View File
@@ -5,6 +5,7 @@
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import bcrypt from "bcryptjs";
import { isWorkerEnvironment } from "../Utils.mjs";
@@ -43,11 +44,16 @@ class BcryptCompare extends Operation {
async run(input, args) {
const hash = args[0];
const match = await bcrypt.compare(input, hash, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
let match;
try {
match = await bcrypt.compare(input, hash, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
} catch (err) {
throw new OperationError(err.toString());
}
return match ? "Match: " + input : "No match";