Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
password: req.param('password')
}
// REGEX to match:
// * Between 4 to 64 characters
// * Special characters allowed (_)
// * Alphanumeric
// * Must start with a letter
if(!validator.isEmail(user.email))
return res.status(500).json({ error: "Invalid Email", code: "!U" });
// REGEX to match:
// * Between 2 to 256 characters
// * Special characters allowed (&)
// * Alpha
if((!validator.matches(user.name, /^([ \u00c0-\u01ffa-zA-Z-\&'\-])+$/))&&(validator.isLength(user.name,2,256)))
return res.status(500).json({ error: "Invalid Name", code: "!N" });
// REGEX to match:
// * Between 6 to 20 characters
// * Special characters allowed (@,$,!,%,*,?,&)
// * Alphanumeric
if(!validator.matches(user.password, /^(?=.*[a-zA-Z])[A-Za-z\d$@$!%*?&]{6,20}/))
return res.status(500).json({ error: "Invalid Password", code: "!P" });
bcrypt.hash(user.password, 10, function(error, hash) {
if(error) return res.status(500).json({ error: error });
console.log(hash);
req.database.models.users.create({
email: user.email,
name: user.name,
emptyPath: false,
newlinePath: false,
nonIntegerMode: false,
numericUser: false,
numericGroup: false
},
warnings = {
nonStandardMode: false
},
i, file;
for (i = 0; i < files.length; i++) {
file = files[i];
// Check path.
if (!validator.isLength(file.path, 1)) {
errors.emptyPath = true;
} else if (validator.contains(file.path, '\n')) {
errors.newlinePath = true;
}
// Check mode.
if (validator.isLength(file.mode, 1)) {
validateMode(file.mode, errors, warnings);
}
if (validator.isLength(file.user, 1) && validator.isInt(file.user)) {
errors.numericUser = true;
}
if (validator.isLength(file.group, 1) && validator.isInt(file.group)) {
errors.numericGroup = true;
if (photoUrl && typeof(photoUrl) === 'function'){
callback = photoUrl
photoUrl = null;
}
if (typeof(callback) !== 'function'){
throw new Error('No valid callback function defined');
return;
}
if (typeof(token) !== 'string' || token.trim().length === 0){
callback(utils.invalidArgumentError('Token'));
return;
}
if (!name || !validator.isLength(name, {min: 2})){
callback(utils.invalidArgumentError('Name'));
return;
}
if (photoUrl && !validator.isURL(photoUrl)) {
callback(utils.invalidArgumentError('Photo Url. Not a valid URL'));
return;
}
var payload = {
idToken: token,
displayName: name,
returnSecureToken: true
}
if (photoUrl)
function validatePasswordLength(password) {
return validator.isLength(password, 8);
}
emailSubject(model) {
if (!validator.isLength(model.emailSubject || '', 0, 300)) {
model.errors.add('emailSubject', 'Email Subject cannot be longer than 300 characters.');
this.invalidate();
}
},
const addErrorAndSanitizedData = ( fieldName, errorContent, min, max, type = '', required ) => {
const postCodeLocale = config.postCodeLocale ? config.postCodeLocale : '';
/**
* Please note that this isEmpty() belongs to validator and not our custom function defined above.
*
* Check for error and if there is no error then sanitize data.
*/
if ( ! validator.isLength( data[ fieldName ], { min, max } ) ){
errors[ fieldName ] = `${errorContent} must be ${min} to ${max} characters`;
}
if ( 'email' === type && ! validator.isEmail( data[ fieldName ] ) ){
errors[ fieldName ] = `${errorContent} is not valid`;
}
if ( 'phone' === type && ! validator.isMobilePhone( data[ fieldName ] ) ) {
errors[ fieldName ] = `${errorContent} is not valid`;
}
if ( 'postCode' === type && postCodeLocale && ! validator.isPostalCode( data[ fieldName ], postCodeLocale ) ) {
errors[ fieldName ] = `${errorContent} is not valid`;
}
if ( required && validator.isEmpty( data[ fieldName ] ) ) {
module.exports = function validateFupInput(data) {
let errors = {};
data.text = validText(data.text) ? data.text : '';
if (!Validator.isLength(data.text, {min: 25, max: 280 })) {
errors.text = 'Fup must be between 25 and 280 characters';
}
if (Validator.isEmpty(data.text)) {
errors.text = 'Text field is required'
}
return {
errors,
isValid: Object.keys(errors).length === 0
}
}
function isAlphaNumeric(str, options){
var isValid = validator.isAlphanumeric(str);
if(isValid && !_.isUndefined(options)){
isValid = validator.isLength(str, options.min, options.max);
}
return isValid;
}
if (!Validator.isLength(data.username, { min: 5, max: 10 })) {
errors.username = "Username must be between 5 and 10 characters.";
}
if (Validator.isEmpty(data.username)) {
errors.username = "Username field is required.";
}
if (Validator.isEmpty(data.age)) {
errors.age = "Age field is required.";
}
if (!Validator.isNumeric(data.age)) {
errors.age = "Age must be a number between 12 and 100.";
}
if (!Validator.isLength(data.password, { min: 5, max: 10 })) {
errors.password = "Password must be between 5 and 10 characters.";
}
if (Validator.isEmpty(data.password)) {
errors.password = "Password field is required.";
}
if(!Validator.equals(data.password, data.password2)) {
errors.password2 = "Password fields must match.";
}
return {
errors,
isValid: Object.keys(errors).length === 0
}
}
validateForm() {
const { username, password } = this.state;
formRules[0].valid = !!validator.isLength(username, { min: 5 });
formRules[1].valid = !!validator.isHalfWidth(username);
formRules[2].valid = !!validator.isLength(password, { min: 8 });
this.setState({
valid: formRules.reduce((res, cur) => ({ valid: res.valid && cur.valid }))
.valid,
});
}