//validator.js

//This is not a recommended password policy, this is purely an example that allows me to use nodeunit
var minimumLength = 12;
var minimumCriteria  = 4; //if you only want to impose 2 of the 4 possible criteria, simply change this to 2
var hasNumeric = /\d+/;
var hasUpper = /[A-Z]+/;
var hasLower = /[a-z]+/;
var hasSpecial = /[!\"£$%^&\*()_\+\-={}\[\];'#:@~,\.\/<>\\?\|]/;

//use the unary plus to convert from true/false to 1/0
//could use the double bitwise not too ~~
exports.validate = function (value) {
  if (typeof value !== 'string') {
		throw new Error('Expected a string');
	}

	if (value.length < minimumLength) {
		throw new Error('String too short');
	}

	if (((+hasNumeric.test(value)) +
		(+hasUpper.test(value)) +
		(+hasLower.test(value)) +
		(+hasSpecial.test(value))) < minimumCriteria) {
		return false;
	}
	return true;
};