Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions waspc/data/Generator/templates/sdk/wasp/auth/password.ts
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,
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.

Loading
Loading