Popular Vulnerable Code

ElephantsElephants

Yesterday I shot an elephant in my pajamas. How he got in my pajamas I don’t know.
- Groucho Marx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


Drupal.evaluatePasswordStrength = function (password, translate) {

var weaknesses = 0, strength = 100, msg = [];
var hasLowercase = password.match(/[a-z]+/);
var hasUppercase = password.match(/[A-Z]+/);
var hasNumbers = password.match(/[0-9]+/);
var hasPunctuation = password.match(/[^a-zA-Z0-9]+/);

// If there is a username edit box on the page,compare password to that,otherwise
// use value from the database.

var usernameBox = $('input.username');
var username = (usernameBox.length > 0) ? usernameBox.val() : translate.username;

// Lose 10 points for every character less than 6.

if (password.length < 6) {
msg.push(translate.tooShort);
strength -= (6 - password.length) * 10;
}

// Count weaknesses.
if (!hasLowercase) {
msg.push(translate.addLowerCase);
weaknesses++;
}

if (!hasUppercase) {
msg.push(translate.addUpperCase);
weaknesses++;
}
if (!hasNumbers) {
msg.push(translate.addNumbers);
weaknesses++;
}

if (!hasPunctuation) {
msg.push(translate.addPunctuation);
weaknesses++;
}

...

// Based on the strength,work out what text should be shown by the password strength meter.
if (strength < 60) {
indicatorText = translate.weak;
} else if (strength < 70) {
indicatorText = translate.fair;
} else if (strength < 80) {
indicatorText = translate.good;
} else if (strength < 100) {
indicatorText = translate.strong;
}

// Assemble the final message.
msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>';
return { strength: strength, message: msg, indicatorText: indicatorText }
If you enjoyed this post,make sure you subscribe to my RSS feed!

2 comments to Elephants

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong><pre lang=""line=""escaped=""highlight="">