import { inject } from '@loopback/context'; import { scryptSync as cryptoHash } from 'crypto'; import { PasswordService } from './types'; import { PasswordServiceBindings } from './keys'; export class AppPasswordService implements PasswordService { constructor( @inject(PasswordServiceBindings.SALT) private _salt: string, @inject(PasswordServiceBindings.LENGTH) private _len: string, ) {} async hash (password: string): Promise { return cryptoHash(password, this._salt, Number(this._len)).toString('base64'); } async verify (pass: string, passIn: string): Promise { return pass === await this.hash(passIn); } }