fix(isHashMatch): check that hash starts with $
Previously, we used argon2 to verify the hash with the password. If the hash didn't start with a $, then it would enter the catch block. Now we check the hash before trying to verify it and we also throw an Error if the verify fails. This makes the isHashMatch function more robust.
This commit is contained in:
@ -166,14 +166,13 @@ export const hash = async (password: string): Promise<string> => {
|
||||
* Used to verify if the password matches the hash
|
||||
*/
|
||||
export const isHashMatch = async (password: string, hash: string) => {
|
||||
if (password === "" || hash === "") {
|
||||
if (password === "" || hash === "" || !hash.startsWith("$")) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
return await argon2.verify(hash, password)
|
||||
} catch (error) {
|
||||
logger.error(error)
|
||||
return false
|
||||
throw new Error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user