Archived
1
0

feat: check for empty str in isHashMatch

This commit is contained in:
Joe Previte
2021-06-07 15:45:11 -07:00
parent 3b50bfc17d
commit 1e55a648a5
4 changed files with 39 additions and 31 deletions

View File

@ -134,6 +134,9 @@ 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 === "") {
return false
}
try {
return await argon2.verify(hash, password)
} catch (error) {
@ -209,11 +212,12 @@ type HandlePasswordValidationArgs = {
* Checks if a password is valid and also returns the hash
* using the PasswordMethod
*/
export async function handlePasswordValidation(
passwordValidationArgs: HandlePasswordValidationArgs,
): Promise<PasswordValidation> {
const { passwordMethod, passwordFromArgs, passwordFromRequestBody, hashedPasswordFromArgs } = passwordValidationArgs
// TODO implement
export async function handlePasswordValidation({
passwordMethod,
passwordFromArgs,
passwordFromRequestBody,
hashedPasswordFromArgs,
}: HandlePasswordValidationArgs): Promise<PasswordValidation> {
const passwordValidation = <PasswordValidation>{
isPasswordValid: false,
hashedPassword: "",
@ -257,10 +261,14 @@ export type IsCookieValidArgs = {
}
/** Checks if a req.cookies.key is valid using the PasswordMethod */
export async function isCookieValid(isCookieValidArgs: IsCookieValidArgs): Promise<boolean> {
export async function isCookieValid({
passwordFromArgs = "",
cookieKey,
hashedPasswordFromArgs = "",
passwordMethod,
}: IsCookieValidArgs): Promise<boolean> {
let isValid = false
const { passwordFromArgs = "", cookieKey, hashedPasswordFromArgs = "" } = isCookieValidArgs
switch (isCookieValidArgs.passwordMethod) {
switch (passwordMethod) {
case "PLAIN_TEXT":
isValid = await isHashMatch(passwordFromArgs, cookieKey)
break