function registration(){} registration.prototype = { minChar : 6, checks: [ /* alphaLower */ { re: /[a-z]/, score: 1 }, /* alphaUpper */ { re: /[A-Z]/, score: 2 }, /* mixture of upper and lowercase */ { re: /([a-z].*[A-Z])|([A-Z].*[a-z])/, score: 2 }, /* numbers */ { re: /(.*[0-9])/, score: 2 }, /* threeNumbers */ { re: /(.*[0-9].*[0-9].*[0-9])/, score: 2 }, /* special chars */ { re: /.[!@#$%^&*?_~]/, score: 3 }, /* multiple special chars */ { re: /(.*[!@#$%^&*?_~].*[!@#$%^&*?_~])/, score: 3 }, { /* let's penalize if the pass contains any of these */ re: /123|456|789|abc|asd|qwe|zxc/, score: -4 }, { /* multiple of the same character, not good */ re: /(.)\1{2}/, score: -3 }, /* all together now, does it look nice? */ { re: /([a-zA-Z0-9].*[!@#$%^&*?_~])|([!@#$%^&*?_~].*[a-zA-Z0-9])/, score: 3 } ], /* banned passwords list, these passwords are bad and you should feel bad */ bannedList : [ '1234', '12345', '123456', '1234567', '12345678', '123456789', '1234567890', '654321', 'default', 'DEFAULT', 'password', 'PASSWORD', 'passw0rd', 'p@ssw0rd', 'qwerty', 'football', 'baseball', 'soccer', 'welcome', 'abc123', '111111', '000000', '77777777', '121212', 'aaaaaa', 'asdfgh', 'asdfghjkl', 'asdfasdf', '1q2w3e4r', '1qaz2wsx', 'dragon', 'master', 'monkey', 'letmein', 'login', 'princess', 'qwertyuiop', 'solo', 'pussy', 'secret' ], getForm : function (countryId){ $.ajax({ url: '/register/get-form?country='+countryId, method: 'get', success: function(html) { $('#form-holder').html(html); setMaskForms(); }, error : function(){ alert('There was an error: please try again'); } }); }, getStates : function(countryId){ $.ajax({ url: '/register/get-states?country='+countryId, method: 'get', dataType: 'json', success: function(json) { $("#register-state").html(json.html); setMaskForms(); }, error : function(){ alert('There was an error: please try again'); } }); }, getCities : function(stateId){ $.ajax({ url: '/register/get-cities?state='+stateId, method: 'get', dataType: 'json', success: function(json) { $("#register-city").html(json.html); setMaskForms(); }, error : function(){ alert('There was an error: please try again'); } }); }, getPasswordStrength : function (pass){ if(pass.length == 0){ $('#password-strength').css('width', 0); return; } var score = 0, minChar = this.minChar, len = pass.length; // Validate with the banned list if(this.bannedList.indexOf(pass) == -1){ diff = len - minChar; (diff >= 7 && (score += 7)) || (diff >= 3 && (score += 4)) || (diff >= 2 && (score += 2)); $.each(this.checks, function(key, check){ pass.match(check.re) && (score += check.score); }); if(len < minChar && score > 1) score = 1; } var percentage = (score / 20) * 100; if(percentage > 100) percentage = 100; if(percentage <0) percentage = 0; $('#password-strength').css('width', percentage); }, timeOutRedirHome : function (url){ setTimeout(function(){ window.location.href = url }, 3000); }, changeDocumentType : function(element){ var documentType = $(element).val(); if(documentType == 2){ $('input[name="document"]').parent().find('label').text('CNPJ'); $('input[name="document"]').attr('data-mask', 'cnpj'); $('input[name="document"]').val(''); }else{ $('input[name="document"]').parent().find('label').text('CPF'); $('input[name="document"]').attr('data-mask', 'cpf'); $('input[name="document"]').val(''); } }, teste : function() { alert('teste'); } } var registration = new registration();