PageSourceSearch

https://www.gvmc.gov.in/wss/static_content/js/password.js

js gvmc.gov.in collected 2026-10-02 13:01:39 UTC 4,949 bytes, 134 lines download raw bytes

1  function chk_text(t, msg, l) 
2    {
3        if ((t.value != '') || (l)) return true;
4        alert(msg);
5        t.focus();
6        return false;
7    }
8    
9	function CheckPassword(f) 
10	{
11        if (chk_text(f.pwd, 'Please enter a password', false) &&
12            chk_text(f.chkpwd, 'Please confirm your password', false)) 
13        {
14            if (f.pwd.value.length<6) 
15                alert("Your password should be at least 6 characters long");
16            else 
17                if (f.pwd.value != f.chkpwd.value) 
18                    alert("Your password and confirmation password do not match. Please check them and try again.");
19                else 
20	                return true;
21        }
22        return false;
23    }
24	
25// password strength
26	function RatePassword(pwd) {
27		var strength  = GetPasswordStrength(pwd);
28		var strengthPercent = ConvertToPercent(strength);
29		document.getElementById("strengthdisplay").innerHTML = GetPasswordStrengthText(strengthPercent);
30		var bardisplayGood = document.getElementById("bardisplayGood");
31		var bardisplayBad = document.getElementById("bardisplayBad");
32		var maxwidth = document.getElementById("bardisplayTable").width;
33		var widthGood = 0;
34		var widthBad = maxwidth;
35		if (strengthPercent >= 80) {
36			// anything above 80% is displayed as 100% good
37			widthGood = maxwidth;
38			widthBad = 0;
39		} else if (strengthPercent >=0 && strengthPercent < 100) {
40			// between zero and 100 display the ratio
41			widthGood = (maxwidth * strengthPercent) / 100;
42			widthBad = maxwidth - widthGood;
43		}
44		bardisplayGood.style.width = widthGood + 'px';
45		bardisplayBad.style.width = widthBad + 'px';
46	}
47	
48      function GetPasswordStrength(pwd) {
49            // zero-length passwords cannot be rated
50            if (pwd.length == 0) {
51                  return -1;
52            }
53            // passwords that are too short are zero-strong
54            if (pwd.length < 6) {
55                  return 0;
56            }
57            var charsSpecial = "";
58            var charsLowercase = "";
59            var charsUppercase = "";
60            var charsNumeric = "";
61            var rating = 0;
62            var bonus = 0;
63            var i;
64            
65            // characters that follow each other in the alphabet are bad
66            var charcode = pwd.charCodeAt(0); 
67            for (i=1; i<pwd.length; i++) {
68                  var diff = pwd.charCodeAt(i) - charcode;
69                  charcode = pwd.charCodeAt(i);
70                  if (diff == 1 || diff == -1) {
71                        pwd = pwd.substring(0, i) + pwd.substring(i-1, i) + pwd.substring(i+1, pwd.length);
72                  }
73            }
74            
75            // put password characters into the right buckets
76            for (i=0; i<pwd.length; i++) {
77                  if (pwd.charCodeAt(i) >= 'a'.charCodeAt(0) && pwd.charCodeAt(i) <='z'.charCodeAt(0)) {
78                        charsLowercase += pwd.substring(i, i+1);
79                  } else if (pwd.charCodeAt(i) >= 'A'.charCodeAt(0) && pwd.charCodeAt(i) <='Z'.charCodeAt(0)) {
80                        charsUppercase += pwd.substring(i, i+1);
81                  } else if (pwd.charCodeAt(i) >= '0'.charCodeAt(0) && pwd.charCodeAt(i) <='9'.charCodeAt(0)) {
82                        charsNumeric += pwd.substring(i, i+1);
83                  } else {
84                        charsSpecial += pwd.substring(i, i+1);
85                  }
86            }
87                        
88            rating = GetDistribution(charsLowercase);
89            rating += GetDistribution(charsUppercase);
90            rating += GetDistribution(charsNumeric);
91            rating += GetDistribution(charsSpecial);
92            
93            if (charsLowercase.length > 0) bonus++;
94            if (charsUppercase.length > 0) bonus++;
95            if (charsNumeric.length > 0) bonus++;
96            if (charsSpecial.length > 0) bonus++;
97            
98            rating = rating * (1 + ((bonus-1) / 4));
99            return rating;
100      }
101
102	function ConvertToPercent(strength) {
103		return 6*strength;
104	}
105		
106	function GetDistribution(str) {
107		var distribution = 0;
108		var uniques = "";
109		var i;
110		for (i=0; i < str.length; i++) {
111			if (uniques.indexOf(str.substring(i, i+1)) == -1) {
112				uniques += str.substring(i, i+1);
113			}
114		}
115		return uniques.length + ((str.length - uniques.length) / 5);
116	}
117	
118	function GetPasswordStrengthText(strength) {
119		if (strength == 0) {
120			return "Too short, minimum 6 characters needed.";
121		} else if (strength > 0 && strength < 20) {
122			return "Very Weak.";
123		} else if (strength >= 20 && strength < 40) {
124			return "Fair.";
125		} else if (strength >= 40 && strength < 60) {
126			return "Good.";
127		} else if (strength >= 60 && strength < 80) {
128			return "Strong.";
129		} else if (strength >= 80) {
130			return "Very Strong.";
131		} else {
132			return "None.";
133		}
134	}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.