-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iam): add pwned password validation (#29)
* [ADD] pwned * [ADD] types sha1 * [REF] hibp integration * lint: use prettier and better wording --------- Co-authored-by: Gustavo Valverde <g.valverde02@gmail.com>
- Loading branch information
1 parent
63c6b15
commit 91ef75d
Showing
6 changed files
with
189 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next/types'; | ||
import { pwnedPassword } from 'hibp'; | ||
import { Crypto } from '@/helpers'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<number | void> | ||
): Promise<void> { | ||
const { token } = req.cookies; | ||
|
||
if (token !== process.env.NEXT_PUBLIC_COOKIE_KEY) { | ||
return res.status(401).send(); | ||
} | ||
|
||
const { password } = req.query; | ||
|
||
if (typeof password !== 'undefined') { | ||
const passwordKey = Array.isArray(password) ? password[0] : password; | ||
const data = await pwnedPassword(Crypto.decrypt(passwordKey)); | ||
res.status(200).json(data); | ||
} else { | ||
res.status(400); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.