We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4dcf3ef + 7f12fab commit faa896cCopy full SHA for faa896c
2 files changed
src/node/util.ts
@@ -166,14 +166,13 @@ export const hash = async (password: string): Promise<string> => {
166
* Used to verify if the password matches the hash
167
*/
168
export const isHashMatch = async (password: string, hash: string) => {
169
- if (password === "" || hash === "") {
+ if (password === "" || hash === "" || !hash.startsWith("$")) {
170
return false
171
}
172
try {
173
return await argon2.verify(hash, password)
174
} catch (error) {
175
- logger.error(error)
176
- return false
+ throw new Error(error)
177
178
179
test/unit/node/util.test.ts
@@ -189,6 +189,17 @@ describe("isHashMatch", () => {
189
const actual = await util.isHashMatch(password, _hash)
190
expect(actual).toBe(false)
191
})
192
+ it("should return false and not throw an error if the hash doesn't start with a $", async () => {
193
+ const password = "hellowpasssword"
194
+ const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
195
+ expect(async () => await util.isHashMatch(password, _hash)).not.toThrow()
196
+ expect(await util.isHashMatch(password, _hash)).toBe(false)
197
+ })
198
+ it("should reject the promise and throw if error", async () => {
199
200
+ const _hash = "$ar2i"
201
+ expect(async () => await util.isHashMatch(password, _hash)).rejects.toThrow()
202
203
204
205
describe("hashLegacy", () => {
0 commit comments