From d6ded9a25f307c86a8fb97c6d7cdf317b391ccc3 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 29 Jan 2021 13:49:05 +0300 Subject: modify check for password strength --- .../static/new/javascript/password_strength.js | 52 +++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/static/new/javascript/password_strength.js b/wqflask/wqflask/static/new/javascript/password_strength.js index aed7c8d0..59fe8584 100644 --- a/wqflask/wqflask/static/new/javascript/password_strength.js +++ b/wqflask/wqflask/static/new/javascript/password_strength.js @@ -1,4 +1,6 @@ // Generated by CoffeeScript 1.8.0 +// edited by alex date on 28/01/2021 + $(function() { var word_score; $("#password").keyup(function() { @@ -6,33 +8,51 @@ $(function() { passtext = $(this).val(); result = zxcvbn(passtext); if (passtext.length < 6) { - $("#password_strength").html(''); - return $("#password_alert").fadeOut(); + let error_message = `the password must have a length greater than six characters` + $("#password_strength").html(error_message); + return $("#password_alert").fadeIn(); } else { word = word_score(result.score); - crack_time = result.crack_time_display; + crack_time = result.crack_times_display.online_throttling_100_per_hour; if (crack_time === "instant") { crack_time = "a second"; } - display = "This is " + word + " password. It can be cracked in " + crack_time + "."; + display = `This is ${word} password.` $("#password_strength").html(display); return $("#password_alert").fadeIn(); } }); return word_score = function(num_score) { - var mapping, result; num_score = parseInt(num_score); console.log("num_score is:", num_score); - mapping = { - 0: "a terrible", - 1: "a bad", - 2: "a mediocre", - 3: "a good", - 4: "an excellent" - }; - console.log("mapping is:", mapping); - result = mapping[num_score]; - console.log("result is:", result); - return result; + + let passwordFeedback = { + 0:{ + color:"#cc1818", + feedback:"a weak" + }, + + 1:{ + color:"#cc1818", + feedback:"a bad" + }, + + 2:{ + color:"#f59105", + feedback:"a mediocre" + }, + + 3:{ + color:"#44ba34", + feedback:"a strong" + }, + 4:{ + color:"green", + feedback:"a stronger" + } + } + + mappingResult = `${passwordFeedback[num_score].feedback}` + return mappingResult; }; }); -- cgit v1.2.3