@@ -134,6 +134,9 @@ export const hash = async (password: string): Promise<string> => {
134134 * Used to verify if the password matches the hash
135135 */
136136export const isHashMatch = async ( password : string , hash : string ) => {
137+ if ( password === "" || hash === "" ) {
138+ return false
139+ }
137140 try {
138141 return await argon2 . verify ( hash , password )
139142 } catch ( error ) {
@@ -209,11 +212,12 @@ type HandlePasswordValidationArgs = {
209212 * Checks if a password is valid and also returns the hash
210213 * using the PasswordMethod
211214 */
212- export async function handlePasswordValidation (
213- passwordValidationArgs : HandlePasswordValidationArgs ,
214- ) : Promise < PasswordValidation > {
215- const { passwordMethod, passwordFromArgs, passwordFromRequestBody, hashedPasswordFromArgs } = passwordValidationArgs
216- // TODO implement
215+ export async function handlePasswordValidation ( {
216+ passwordMethod,
217+ passwordFromArgs,
218+ passwordFromRequestBody,
219+ hashedPasswordFromArgs,
220+ } : HandlePasswordValidationArgs ) : Promise < PasswordValidation > {
217221 const passwordValidation = < PasswordValidation > {
218222 isPasswordValid : false ,
219223 hashedPassword : "" ,
@@ -257,10 +261,14 @@ export type IsCookieValidArgs = {
257261}
258262
259263/** Checks if a req.cookies.key is valid using the PasswordMethod */
260- export async function isCookieValid ( isCookieValidArgs : IsCookieValidArgs ) : Promise < boolean > {
264+ export async function isCookieValid ( {
265+ passwordFromArgs = "" ,
266+ cookieKey,
267+ hashedPasswordFromArgs = "" ,
268+ passwordMethod,
269+ } : IsCookieValidArgs ) : Promise < boolean > {
261270 let isValid = false
262- const { passwordFromArgs = "" , cookieKey, hashedPasswordFromArgs = "" } = isCookieValidArgs
263- switch ( isCookieValidArgs . passwordMethod ) {
271+ switch ( passwordMethod ) {
264272 case "PLAIN_TEXT" :
265273 isValid = await isHashMatch ( passwordFromArgs , cookieKey )
266274 break
0 commit comments