Permalink
Browse files

WINKSTART-800: Update to the password check

  • Loading branch information...
JRMaitre committed May 3, 2012
1 parent 3ee0812 commit ab6db85cd9bdcd28e11482ef75fd32ae88cd8dde
Showing with 11 additions and 30 deletions.
  1. +11 −30 js/winkstart-util.js
View
@@ -1,47 +1,28 @@
( function(winkstart, amplify, $) {
winkstart.is_password_valid = function(password_string, strength) {
- var help_standard = 'The password must contain at least 6 characters and include a letter and a number.',
- help_strong = 'The password must contain at least 8 characters including a non-capitalized letter, a capitalized letter, a number and a special character (!%$...)',
+ var help = {
+ standard: 'The password must contain at least 6 characters and include a letter and a number.',
+ strong: 'The password must contain at least 8 characters including a non-capitalized letter, a capitalized letter, a number and a special character (!%$...)'
+ },
strength = strength || 'standard', //Standard is the default value
- res = password_string.match(winkstart.get_password_regex(strength)),
- alert_message = 'Your password is not valid<br/>';
+ res = password_string.match(winkstart.get_password_regex(strength));
if(res && res[0]) {
return true;
}
else {
- switch(strength) {
- case 'standard':
- alert_message += help_standard;
- break;
-
- case 'strong':
- alert_message += help_strong;
- break;
-
- default: true;
- }
- winkstart.alert(alert_message);
+ winkstart.alert('Your password is not valid<br/>' + help[strength] || '');
return false;
}
};
winkstart.get_password_regex = function(strength) {
- var standard_validation = /(?=^.{6,}$)(?=.*\d)((?=.*[a-z])|(?=.*[A-Z])).*$/g,
- strong_validation = /(?=^.{8,}$)(?![.\n])(?=.*[\!\@\#\$\%\^\&\*\-\_\(\)\[\]\=\+\^])(?=.*[A-Z])(?=.*\d)(?=.*[a-z]).*$/g;
-
- switch(strength) {
- case 'standard':
- return standard_validation;
- break;
-
- case 'strong':
- return strong_validation;
- break;
+ var validation = {
+ standard: /(?=^.{6,}$)(?=.*\d)((?=.*[a-z])|(?=.*[A-Z])).*$/g,
+ strong: /(?=^.{8,}$)(?![.\n])(?=.*[\!\@\#\$\%\^\&\*\-\_\(\)\[\]\=\+\^])(?=.*[A-Z])(?=.*\d)(?=.*[a-z]).*$/g
+ };
- default:
- return standard_validation;
- }
+ return validation[strength || 'standard'];
};
winkstart.log = function(data) {

0 comments on commit ab6db85

Please sign in to comment.