File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -166,14 +166,13 @@ export const hash = async (password: string): Promise<string> => {
166
166
* Used to verify if the password matches the hash
167
167
*/
168
168
export const isHashMatch = async ( password : string , hash : string ) => {
169
- if ( password === "" || hash === "" ) {
169
+ if ( password === "" || hash === "" || ! hash . startsWith ( "$" ) ) {
170
170
return false
171
171
}
172
172
try {
173
173
return await argon2 . verify ( hash , password )
174
174
} catch ( error ) {
175
- logger . error ( error )
176
- return false
175
+ throw new Error ( error )
177
176
}
178
177
}
179
178
Original file line number Diff line number Diff line change @@ -189,6 +189,17 @@ describe("isHashMatch", () => {
189
189
const actual = await util . isHashMatch ( password , _hash )
190
190
expect ( actual ) . toBe ( false )
191
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
+ const password = "hellowpasssword"
200
+ const _hash = "$ar2i"
201
+ expect ( async ( ) => await util . isHashMatch ( password , _hash ) ) . rejects . toThrow ( )
202
+ } )
192
203
} )
193
204
194
205
describe ( "hashLegacy" , ( ) => {
You can’t perform that action at this time.
0 commit comments