dropbox / zxcvbn

Low-Budget Password Strength Estimation
https://www.usenix.org/conference/usenixsecurity16/technical-sessions/presentation/wheeler
MIT License
15k stars 934 forks source link

Test.js help #84

Closed Cr1T1cal closed 9 years ago

Cr1T1cal commented 9 years ago

Hey im having a few difficulties with the test.js im trying to remove the test_passwords and #results Id and only keep the #search-passwords so basicaly i want to just show the the password tryped no examples and one more little bug iv encountered is that iv added a scoller div to the match sequence but it only seems to work on the test_passwords

here my code;


var props_tmpl, results_tmpl, test_passwords, zxcvbn_load_hook;

test_passwords = 'n0Ts0Cr4ck4bL3';
results_tmpl = '{{#results}}\n
\n
\n
\n Password Statistics\n
\n
\n\n\n\n\n
\n
\n
\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
password: {{password}}
entropy: {{entropy}}
composition: {{composition}}
acceptable: {{acceptable}}
crack time (seconds): {{crack_time}}
crack time (display): {{crack_time_display}}
score from 0 to 4:{{score}}
calculation time (ms): {{calc_time}}
\n
\n{{& match_sequence_display}}\n{{/results}}'; props_tmpl = 'match sequence:\n
\n
\n{{& match_sequence_display}}\n
\n{{#match_sequence}}\n\n \n \n \n \n \n \n \n \n \n \n \n {{#cardinality}}\n \n \n \n \n {{/cardinality}}\n {{#rank}}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n {{/rank}}\n {{#l33t}}\n \n \n \n \n \n \n \n \n \n \n \n \n {{/l33t}}\n {{#graph}}\n \n \n \n \n \n \n \n \n \n \n \n \n {{/graph}}\n {{#repeated_char}}\n \n \n \n \n {{/repeated_char}}\n {{#sequence_name}}\n \n \n \n \n \n \n \n \n \n \n \n \n {{/sequence_name}}\n {{#day}}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n {{/day}}\n
\'{{token}}\'
pattern:{{pattern}}
entropy:{{entropy}}
cardinality:{{cardinality}}
dict-name:{{dictionary_name}}
rank:{{rank}}
base-entropy:{{base_entropy}}
upper-entropy:{{uppercase_entropy}}
l33t-entropy:{{l33t_entropy}}
l33t subs:{{sub_display}}
un-l33ted:{{matched_word}}
graph: {{graph}}
turns: {{turns}}
shifted keys: {{shifted_count}}
repeat-char:\'{{repeated_char}}\'
sequence-name:{{sequence_name}}
sequence-size{{sequence_space}}
ascending:{{ascending}}
day:{{day}}
month:{{month}}
year:{{year}}
separator:\'{{separator}}\'
\n{{/match_sequence}}\n
'; zxcvbn_load_hook = function() { return $(function() { var last_q, password, r, rendered, results_lst, _i, _len, _listener, _ref; results_lst = []; _ref = test_passwords.split('\n'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { password = _ref[_i]; if (!(password)) continue; r = zxcvbn(password); comp_result = cyg_test_composition(password, 'Password'); r.composition = comp_result["message"]; if (comp_result["valid"] && r.entropy >= 40) { r.acceptable = 'yes'; } else { r.acceptable = 'no'; } r.match_sequence_display = Mustache.render(props_tmpl, r); results_lst.push(r); } rendered = Mustache.render(results_tmpl, { results: results_lst }); $('#results').html(rendered); last_q = ''; _listener = function() { var current, results; current = $('#register_password').val(); if (!current) { $('#search-results').html(''); return; } if (current !== last_q) { last_q = current; r = zxcvbn(current); comp_result = cyg_test_composition(current, 'Password'); r.composition = comp_result["message"]; if (comp_result["valid"] && r.entropy >= 40) { r.acceptable = 'yes'; } else { r.acceptable = 'no'; } r.match_sequence_display = Mustache.render(props_tmpl, r); results = { results: [r] }; rendered = Mustache.render(results_tmpl, results); return $('#search-results').html(rendered); } }; return setInterval(_listener, 100); }); };

PS sorry didnt know how to stop results_tmpl = and props_tmpl = from going weird but there no actually like that

I would appreciate any help as my js iisnt that good

lowe commented 9 years ago

Hi @Cr1T1cal , I think this will do what you want.

In demo/demo.coffee, delete these lines (you can also delete test_passwords and results_tmpl if you like):

    results_lst = []
    for password in test_passwords.split('\n') when password
      r = zxcvbn(password)
      r.match_sequence_display = Mustache.render(props_tmpl, r)
      results_lst.push r

    rendered = Mustache.render(results_tmpl, {
      results: results_lst,
    })
    $('#results').html(rendered)

In demo/index.html, remove these lines:

<div id="examples-container">
<h1 id="examples">examples</h1>
<div id="results">
</div>

From the command line run,

cd zxcvbn/demo
coffee -c demo.coffee

then load demo/index.html in your browser.