Vpassword
Bun

variable

password

const password: { hash(password: StringOrBuffer, algorithm?: Argon2Algorithm | 'argon2id' | 'argon2d' | 'argon2i' | BCryptAlgorithm | 'bcrypt'): Promise<string>; hashSync(password: StringOrBuffer, algorithm?: Argon2Algorithm | 'argon2id' | 'argon2d' | 'argon2i' | BCryptAlgorithm | 'bcrypt'): string; verify(password: StringOrBuffer, hash: StringOrBuffer, algorithm?: 'argon2id' | 'argon2d' | 'argon2i' | 'bcrypt'): Promise<boolean>; verifySync(password: StringOrBuffer, hash: StringOrBuffer, algorithm?: 'argon2id' | 'argon2d' | 'argon2i' | 'bcrypt'): boolean }

Hash and verify passwords using argon2 or bcrypt. The default is argon2. Password hashing functions are necessarily slow, and this object will automatically run in a worker thread.

Example with argon2

import {password} from "bun";

const hash = await password.hash("hello world");
const verify = await password.verify("hello world", hash);
console.log(verify); // true

Example with bcrypt

import {password} from "bun";

const hash = await password.hash("hello world", "bcrypt");
// algorithm is optional, will be inferred from the hash if not specified
const verify = await password.verify("hello world", hash, "bcrypt");

console.log(verify); // true