1.0.0 • Published 3 years ago

phpass-to-argon2 v1.0.0

Weekly downloads
4
License
ISC
Repository
gitlab
Last release
3 years ago

phpass-to-argon2

Methods for checking passwords against phpass or argon2 hashes, and upgrading then to argon2 where needed.

import verify, { hash } from 'phpass-to-argon2';

/**
 * An example login function using phpass-to-argon2
 * @param user The user object to verify against
 * @param password The password submitted by the login form
 */
export default async function login(user, password) {
	return verify(
		// Supply the password and the hash to verify against
		user.passwordHash,
		password,

		// Supply a function for updating the hash when needed
		async newHash => {
			user.passwordHash = newHash;
			await user.save();
		}
	)
}

// We also export the argon2 hash method
// for setting the password normally.
export async function updatePassword(user, newPassword) {
	user.passwordHash = await hash(newPassword);
	await user.save();
}

Modules

phpass-to-argon2

verify

Verify a password against a phpass or argon2 hash. If the update argument is passed, it will be called when a password hash needs updating from phpass to argon2

ParamTypeDescription
hashstringThe hash to compare with
passwordstringThe password to compare
updatefunctionA function to execute when the stored hash needs updating, taking the new hash as the first argument
optionsobjectThe argon2 options object

hash ⇒ string

Hash a password using argon2

Returns: string - The hashed password

ParamTypeDescription
passwordstringThe password to be hashed
optionsobjectThe argon2 options object

needsUpdate ⇒ boolean

Check if a hash needs to be updated

ParamTypeDescription
hashstringThe hash to check
1.0.0

3 years ago