diff --git a/index.js b/index.js index 103d8f1..f366fa2 100644 --- a/index.js +++ b/index.js @@ -13,18 +13,18 @@ module.exports = function(schema, options) { options.encoding = options.encoding || 'hex'; options.digestAlgorithm = options.digestAlgorithm || 'sha256'; // To get a list of supported hashes use crypto.getHashes() - options.passwordValidator = - options.passwordValidator || - function(password, cb) { - cb(null); - }; - options.passwordValidatorAsync = - options.passwordValidatorAsync || - function(password) { - return new Promise((resolve, reject) => { - options.passwordValidator(password, err => (err ? reject(err) : resolve())); - }); - }; + function defaultPasswordValidator(password, cb) { + cb(null); + } + + function defaultPasswordValidatorAsync(password) { + return new Promise((resolve, reject) => { + options.passwordValidator(password, err => (err ? reject(err) : resolve())); + }); + } + + options.passwordValidator = options.passwordValidator || defaultPasswordValidator; + options.passwordValidatorAsync = options.passwordValidatorAsync || defaultPasswordValidatorAsync; // Populate field names with defaults if not set options.usernameField = options.usernameField || 'username'; diff --git a/lib/errors.js b/lib/errors.js index 1251ce5..2b2dd7f 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -3,7 +3,7 @@ const generaterr = require('generaterr'); const AuthenticationError = generaterr('AuthenticationError'); module.exports = { - AuthenticationError: AuthenticationError, + AuthenticationError, IncorrectUsernameError: generaterr('IncorrectUsernameError', null, { inherits: AuthenticationError }), IncorrectPasswordError: generaterr('IncorrectPasswordError', null, { inherits: AuthenticationError }), MissingUsernameError: generaterr('MissingUsernameError', null, { inherits: AuthenticationError }),