-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordstrength.php
174 lines (147 loc) · 3 KB
/
passwordstrength.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<html>
<head>
<style>
body
{
/*ie needs this*/
margin:0px;
padding:0px;
/*set global font settings*/
font-size:10px;
font-family:Tahoma,Verdana,Arial;
}
a:hover
{
color:#fff;
}
#user_registration
{
border:1px solid #cccccc;
margin:auto auto;
margin-top:100px;
width:400px;
}
#user_registration label
{
display: block; /* block float the labels to left column, set a width */
float: left;
width: 70px;
margin: 0px 10px 0px 5px;
text-align: right;
line-height:1em;
font-weight:bold;
}
#user_registration input
{
width:250px;
}
#user_registration p
{
clear:both;
}
#submit
{
border:1px solid #cccccc;
width:100px !important;
margin:10px;
}
h1
{
text-align:center;
}
#passwordStrength
{
height:10px;
display:block;
float:left;
}
.strength0
{
width:250px;
background:#cccccc;
}
.strength1
{
width:50px;
background:#ff0000;
}
.strength2
{
width:100px;
background:#ff5f5f;
}
.strength3
{
width:150px;
background:#56e500;
}
.strength4
{
background:#4dcd00;
width:200px;
}
.strength5
{
background:#399800;
width:250px;
}
</style>
</style>
<script>
function passwordStrength(password)
{
var desc = new Array();
desc[0] = "Very Weak";
desc[1] = "Weak";
desc[2] = "Better";
desc[3] = "Medium";
desc[4] = "Strong";
desc[5] = "Strongest";
var score = 0;
//if password bigger than 6 give 1 point
if (password.length > 6) score++;
//if password has both lower and uppercase characters give 1 point
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;
//if password has at least one number give 1 point
if (password.match(/\d+/)) score++;
//if password has at least one special caracther give 1 point
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
//if password bigger than 12 give another 1 point
if (password.length > 12) score++;
document.getElementById("passwordDescription").innerHTML = desc[score];
document.getElementById("passwordStrength").className = "strength" + score;
}
</script>
</head>
<body>
<form method="post" action="" id="user_registration" name="user_registration">
<p><h1>Password strength metter</h1></p>
<p>
<label for="user">Username</label><input type="text" name="user" id="user"/>
</p>
<p>
<label for="name">Name</label><input type="text" name="name" id="name"/>
</p>
<p>
<label for="surname">Surname</label><input type="text" name="surname" id="surname"/>
</p>
<p>
<label for="email">E-mail</label><input type="text" name="email" id="email"/>
</p>
<p>
<label for="pass">Password</label><input type="password" name="pass" id="pass" onkeyup="passwordStrength(this.value)"/>
</p>
<p>
<label for="pass2">Confirm Password</label><input type="password" name="pass2" id="pass2"/>
</p>
<p>
<label for="passwordStrength">Password strength</label>
<div id="passwordDescription">Password not entered</div>
<div id="passwordStrength" class="strength0"></div>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Register">
</p>
</form>
</body>
</html>