aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/static/new/javascript/password_strength.js
blob: a8a45f7d5914d6a325d081e6e20eef5551d830f3 (plain)
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
// Generated by CoffeeScript 1.8.0

$(function() {
  var word_score;
  $("#password").keyup(function() {
    var crack_time, display, passtext, result, word;
    passtext = $(this).val();
    result = zxcvbn(passtext);
    if (passtext.length < 6) {
      let error_message = `<strong style="color:red;">the password must have a length greater than six characters</strong>`
      $("#password_strength").html(error_message);
      return $("#password_alert").fadeIn();
    } else {
      word = word_score(result.score);
      crack_time = result.crack_times_display.online_throttling_100_per_hour;
      if (crack_time === "instant") {
        crack_time = "a second";
      }
      display = `This is ${word} password.`
      $("#password_strength").html(display);
      return $("#password_alert").fadeIn();
    }
  });
  return word_score = function(num_score) {
    num_score = parseInt(num_score);
    console.log("num_score is:", num_score);

    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"
      }
    }

    let mappingResult = `<strong style="color:${passwordFeedback[num_score].color};">${passwordFeedback[num_score].feedback}</strong>`
    return mappingResult;
  };
});