1 |
|
2 | var feedback, scoring;
|
3 |
|
4 | scoring = require('./scoring');
|
5 |
|
6 | feedback = {
|
7 | default_feedback: {
|
8 | warning: '',
|
9 | suggestions: ["Use a few words, avoid common phrases", "No need for symbols, digits, or uppercase letters"]
|
10 | },
|
11 | get_feedback: function(score, sequence) {
|
12 | var extra_feedback, i, len, longest_match, match, ref;
|
13 | if (sequence.length === 0) {
|
14 | return this.default_feedback;
|
15 | }
|
16 | if (score > 2) {
|
17 | return {
|
18 | warning: '',
|
19 | suggestions: []
|
20 | };
|
21 | }
|
22 | longest_match = sequence[0];
|
23 | ref = sequence.slice(1);
|
24 | for (i = 0, len = ref.length; i < len; i++) {
|
25 | match = ref[i];
|
26 | if (match.token.length > longest_match.token.length) {
|
27 | longest_match = match;
|
28 | }
|
29 | }
|
30 | feedback = this.get_match_feedback(longest_match, sequence.length === 1);
|
31 | extra_feedback = 'Add another word or two. Uncommon words are better.';
|
32 | if (feedback != null) {
|
33 | feedback.suggestions.unshift(extra_feedback);
|
34 | if (feedback.warning == null) {
|
35 | feedback.warning = '';
|
36 | }
|
37 | } else {
|
38 | feedback = {
|
39 | warning: '',
|
40 | suggestions: [extra_feedback]
|
41 | };
|
42 | }
|
43 | return feedback;
|
44 | },
|
45 | get_match_feedback: function(match, is_sole_match) {
|
46 | var layout, warning;
|
47 | switch (match.pattern) {
|
48 | case 'dictionary':
|
49 | return this.get_dictionary_match_feedback(match, is_sole_match);
|
50 | case 'spatial':
|
51 | layout = match.graph.toUpperCase();
|
52 | warning = match.turns === 1 ? 'Straight rows of keys are easy to guess' : 'Short keyboard patterns are easy to guess';
|
53 | return {
|
54 | warning: warning,
|
55 | suggestions: ['Use a longer keyboard pattern with more turns']
|
56 | };
|
57 | case 'repeat':
|
58 | warning = match.base_token.length === 1 ? 'Repeats like "aaa" are easy to guess' : 'Repeats like "abcabcabc" are only slightly harder to guess than "abc"';
|
59 | return {
|
60 | warning: warning,
|
61 | suggestions: ['Avoid repeated words and characters']
|
62 | };
|
63 | case 'sequence':
|
64 | return {
|
65 | warning: "Sequences like abc or 6543 are easy to guess",
|
66 | suggestions: ['Avoid sequences']
|
67 | };
|
68 | case 'regex':
|
69 | if (match.regex_name === 'recent_year') {
|
70 | return {
|
71 | warning: "Recent years are easy to guess",
|
72 | suggestions: ['Avoid recent years', 'Avoid years that are associated with you']
|
73 | };
|
74 | }
|
75 | break;
|
76 | case 'date':
|
77 | return {
|
78 | warning: "Dates are often easy to guess",
|
79 | suggestions: ['Avoid dates and years that are associated with you']
|
80 | };
|
81 | }
|
82 | },
|
83 | get_dictionary_match_feedback: function(match, is_sole_match) {
|
84 | var ref, result, suggestions, warning, word;
|
85 | warning = match.dictionary_name === 'passwords' ? is_sole_match && !match.l33t && !match.reversed ? match.rank <= 10 ? 'This is a top-10 common password' : match.rank <= 100 ? 'This is a top-100 common password' : 'This is a very common password' : match.guesses_log10 <= 4 ? 'This is similar to a commonly used password' : void 0 : match.dictionary_name === 'english' ? is_sole_match ? 'A word by itself is easy to guess' : void 0 : (ref = match.dictionary_name) === 'surnames' || ref === 'male_names' || ref === 'female_names' ? is_sole_match ? 'Names and surnames by themselves are easy to guess' : 'Common names and surnames are easy to guess' : '';
|
86 | suggestions = [];
|
87 | word = match.token;
|
88 | if (word.match(scoring.START_UPPER)) {
|
89 | suggestions.push("Capitalization doesn't help very much");
|
90 | } else if (word.match(scoring.ALL_UPPER)) {
|
91 | suggestions.push("All-uppercase is almost as easy to guess as all-lowercase");
|
92 | }
|
93 | if (match.reversed && match.token.length >= 4) {
|
94 | suggestions.push("Reversed words aren't much harder to guess");
|
95 | }
|
96 | if (match.l33t) {
|
97 | suggestions.push("Predictable substitutions like '@' instead of 'a' don't help very much");
|
98 | }
|
99 | result = {
|
100 | warning: warning,
|
101 | suggestions: suggestions
|
102 | };
|
103 | return result;
|
104 | }
|
105 | };
|
106 |
|
107 | module.exports = feedback;
|
108 |
|
109 |
|