import * as bcrypt from 'bcryptjs' ; import Text from './Text' ; export default class Hash extends Text { saltRounds : number ; constructor ( min = null , max = null , flags = null , saltRounds = 10 ) { super ( min , max , undefined , flags ) ; this . saltRounds = saltRounds ; } async parse ( value ) { if ( await super . parse ( value ) ) { return bcrypt . hash ( value , this . saltRounds ) ; } return undefined ; } static async validate ( value , hash ) { return bcrypt . compare ( value , hash ) ; } }