-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Replace oslo/password
with directly using @node-rs/argon2
#2210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import { Argon2id } from 'oslo/password' | ||
import { hash, verify, Version, type Options } from "@node-rs/argon2"; | ||
|
||
const argon2id = new Argon2id() | ||
// The options are the same as the ones used in the oslo/password library | ||
const hashingOptions: Options = { | ||
memoryCost: 19456, | ||
timeCost: 2, | ||
outputLen: 32, | ||
parallelism: 1, | ||
version: Version.V0x13, | ||
}; | ||
|
||
// PRIVATE API | ||
export const hashPassword = async (password: string): Promise<string> => { | ||
return argon2id.hash(password) | ||
export async function hashPassword(password: string): Promise<string> { | ||
return hash(normalizePassword(password), hashingOptions); | ||
} | ||
|
||
// PRIVATE API | ||
export const verifyPassword = async (hashedPassword: string, password: string): Promise<void> => { | ||
const isValidPassword = await argon2id.verify(hashedPassword, password) | ||
if (!isValidPassword) { | ||
throw new Error('Invalid password.') | ||
export async function verifyPassword( | ||
hashedPassword: string, | ||
sodic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
password: string | ||
): Promise<void> { | ||
const validPassword = await verify( | ||
hashedPassword, | ||
normalizePassword(password), | ||
hashingOptions | ||
); | ||
if (!validPassword) { | ||
throw new Error("Invalid password"); | ||
} | ||
} | ||
|
||
// We are normalising the password to ensure that the password is always hashed in the same way | ||
// We have the same normalising process as oslo/password did in the past | ||
function normalizePassword(password: string): string { | ||
return password.normalize("NFKC"); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.