@@ -134,6 +134,9 @@ export const hash = async (password: string): Promise<string> => {
134
134
* Used to verify if the password matches the hash
135
135
*/
136
136
export const isHashMatch = async ( password : string , hash : string ) => {
137
+ if ( password === "" || hash === "" ) {
138
+ return false
139
+ }
137
140
try {
138
141
return await argon2 . verify ( hash , password )
139
142
} catch ( error ) {
@@ -209,11 +212,12 @@ type HandlePasswordValidationArgs = {
209
212
* Checks if a password is valid and also returns the hash
210
213
* using the PasswordMethod
211
214
*/
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 > {
217
221
const passwordValidation = < PasswordValidation > {
218
222
isPasswordValid : false ,
219
223
hashedPassword : "" ,
@@ -257,10 +261,14 @@ export type IsCookieValidArgs = {
257
261
}
258
262
259
263
/** 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 > {
261
270
let isValid = false
262
- const { passwordFromArgs = "" , cookieKey, hashedPasswordFromArgs = "" } = isCookieValidArgs
263
- switch ( isCookieValidArgs . passwordMethod ) {
271
+ switch ( passwordMethod ) {
264
272
case "PLAIN_TEXT" :
265
273
isValid = await isHashMatch ( passwordFromArgs , cookieKey )
266
274
break
0 commit comments