refactor: add functions to check hash password

This commit is contained in:
Joe Previte
2021-05-19 16:17:32 -07:00
parent f35120c0a3
commit aaf044728f
4 changed files with 74 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import { normalize, Options } from "../common/util"
import { AuthType, DefaultedArgs } from "./cli"
import { commit, rootPath } from "./constants"
import { Heart } from "./heart"
import { hash } from "./util"
import { isHashMatch } from "./util"
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
@ -67,7 +67,7 @@ export const authenticated = (req: express.Request): boolean => {
req.cookies.key &&
(req.args["hashed-password"]
? safeCompare(req.cookies.key, req.args["hashed-password"])
: req.args.password && safeCompare(req.cookies.key, hash(req.args.password)))
: req.args.password && isHashMatch(req.args.password, req.cookies.key))
)
default:
throw new Error(`Unsupported auth type ${req.args.auth}`)