File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 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> => {
166166 * Used to verify if the password matches the hash
167167 */
168168export const isHashMatch = async ( password : string , hash : string ) => {
169- if ( password === "" || hash === "" ) {
169+ if ( password === "" || hash === "" || ! hash . startsWith ( "$" ) ) {
170170 return false
171171 }
172172 try {
173173 return await argon2 . verify ( hash , password )
174174 } catch ( error ) {
175- logger . error ( error )
176- return false
175+ throw new Error ( error )
177176 }
178177}
179178
Original file line number Diff line number Diff line change @@ -189,6 +189,17 @@ describe("isHashMatch", () => {
189189 const actual = await util . isHashMatch ( password , _hash )
190190 expect ( actual ) . toBe ( false )
191191 } )
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+ } )
192203} )
193204
194205describe ( "hashLegacy" , ( ) => {
You can’t perform that action at this time.
0 commit comments