-
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
49a0834
commit b7ea798
Showing
6 changed files
with
87 additions
and
45 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
7a5ee94e69cf3c51f830ec8554b70732b07e624b | ||
c430adebb4598c04f3378557d9d1f330dc26253d |