-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
209 lines (204 loc) · 5.95 KB
/
index.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Main page</title>
<style>
* {
margin: 0;
padding: 0;
}
#testPassword {
height: 50vh;
background-color: green;
}
#GeneratePassword{
height: 50vh;
background-color: green;
}
.passwordCopy{
background-color: green;
}
.passwordParam{
background-color: green;
}
.center {
display: flex;
justify-content: center;
align-items: center;
}
#pass {
width: 30vw;
height: 3em;
border: 2px solid black;
border-radius: 3rem 0 0 3rem;
}
#password {
width: 30vw;
height: 4em;
border: 2px solid black;
}
.btn {
height: 3.3em;
border: 2px solid black;
border-radius: 0 3rem 3rem 0;
width: 5vw;
margin: -0.5em;
}
.button {
height: 4.4em;
border: 2px solid black;
border-radius: 0 3rem 3rem 0;
width: 5vw;
margin: -0.5em;
}
.Message {
font-size: 5.15em;
color: white;
}
.grid{
display:grid;
}
.new{
margin-top:1em;
padding: 1em;
border: 1px solid black;
border-radius: 2rem;
}
input{
padding: 0 10px;
}
#GeneratePassword>.container{
width: 80%;
height: 60%;
background-color: #FFF;
}
</style>
</head>
<body>
<div id="testPassword" class="center">
<div class="container">
<div class="Message center">
<span>Check my Password?</span>
</div>
<div class="form center">
<form action="index.php" method="post">
<input type="text" name="pass" id="pass"required/>
<input type="submit" value="Submit" class="btn" />
</form>
</div>
<div class="center">
<h1>
<?php require 'checkPassword.php';
if (isset($_POST['pass'])) {
echo ($_POST["pass"]) . " is " . checkPasswordSecurity($_POST["pass"]) . " as a password";
}?>
</h1>
</div>
</div>
</div>
<div class="passwordCopy">
<div class="center">
<h4>
Here is a secure password for you.
</h4>
</div>
<div class= "center">
<input type="text" name="password" id="password" value="<?php generateNewPassword();?>">
<button class="button" onclick="copyFunction()">Copy</button>
</div>
<div class="center">
<button class = "new" form="passwordProp">Generate new password</button>
</div>
</div>
<div id="GeneratePassword" class="center">
<div class="container">
<div class="box">
<div style="border-bottom: 1px solid gray; width:100%;">
<h3>Customize password</h3>
<hr>
</div>
<form id="passwordProp" name="form_A" action="index.php" method="POST" class="grid">
<div>
<span>Password Length</span>
<div>
<input type="range" name="PLength" id="number" max=50 value=12 onchange="changeSlide()">
<input type="number" name="choosen" id="chosen" value="12" style="width:3em;">
</div>
</div>
<div style="grid-column:2;">
<input type="checkbox" name="LowerCase" id="lcase" checked><label for="lowerCase">Lower Case</label>
<br>
<input type="checkbox" name="UpperCase" id="ucase" checked><label for="upperCase">Upper Case</label>
<br>
<input type="checkbox" name="Number" id="num" checked><label for="Number">Numbers</label>
<br>
<input type="checkbox" name="Special" id="spec" checked><label for="Special">Special Characters</label>
</div>
<div>
</div>
</form>
</div>
</div>
</div>
<div class="center passwordParam">
<div class="container">
<span>It checks for following parameter in password</span>
<ul>
<li>has 8 minimum characters</li>
<li>contains at least one lowercase, uppercase, number and special characters</li>
</ul>
</div>
</div>
<script>
function copyFunction() {
var copyText = document.getElementById("password");
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value)
}
var slider = document.getElementById("number");
var output = document.getElementById("chosen");
function changeSlide() {
output.value = slider.value;
}
</script>
</body>
</html>
<?php
$lowerCase = 'abcdefghijklmnopqrstuvwxyz';
$upperCase = strtoupper($lowerCase);
$number = '0123456789';
$special = '!@#$%^&*()_+,.<>/?;:[]{}\|';
function password_generate($chars)
{
global $lowerCase,$upperCase,$number,$special;
$data = $lowerCase . $upperCase . $number . $special;
echo substr(str_shuffle($data), 0, $chars);
}
function generateNewPassword(){
global $lowerCase,$upperCase,$number,$special;
if(!isset($_POST["PLength"])){
echo("A");
password_generate(12);
}else{
$len = $_POST["PLength"];
$data = null;
if(isset($_POST["LowerCase"])){
$data = $data . $lowerCase;
}
if(isset($_POST["UpperCase"])){
$data = $data . $upperCase;
}
if(isset($_POST["Number"])){
$data = $data . $number;
}
if(isset($_POST["Special"])){
$data = $data . $special;
}
echo substr(str_shuffle($data), 0, $len);
}
}
?>