import * as bcrypt from 'bcrypt' ; import IHashMethod from '../IHashMethod' ; import IBcryptOptions from './IBcryptOptions' ; export function hash ( password , salt ? , options = { } ) { if ( ! salt ) { return bcrypt . genSalt ( options . saltRounds ) . then ( ( salt ) => bcrypt . hash ( password , salt ) ) ; } return bcrypt . hash ( password , salt ) ; } export function compare ( userPassword , hashedPassword , options ? ) { return bcrypt . compare ( userPassword , hashedPassword ) ; } export default function bcryptProvider ( options ) { return { hash : ( password , salt ? ) => hash ( password , salt , options ) , compare : ( userPassword , hashedPassword ) => compare ( userPassword , hashedPassword , options ) , } as IHashMethod ; }