-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
434 lines (329 loc) · 13.9 KB
/
index.html
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Term project registration page</title>
<link rel="stylesheet" type="text/css" href="css/index_style.css" />
</head>
<body>
<div class="contianer">
<form>
<div class="conatiner-uth">
<br>
<h1 class="title">MyPass</h1>
<h2>Register Account</h2>
<!--user input feilds-->
<div class="userInput">
<input type="text" id="username" placeholder="Enter Username" required>
</div>
<div class="userInput">
<input type="email" id="email" placeholder="Enter Email Address" required>
</div>
<div class="userInput">
<p>Security Questions</p>
<input type="text" id="questions-1" placeholder="Favorite Childhood Toy or Game:" required>
<input type="text" id="questions-2" placeholder="Dream Vacation Destination:" required>
<input type="text" id="questions-3" placeholder="First Job or Company:" required>
</div>
<div class="userInput">
<input type="text" id="password" placeholder="Enter Password" required>
<button type="button" id="generatePasswordBtn">Generate Password</button>
<!-- series of checkboxes that will allow the user to generate what type of password they would like to generate -->
<input type="checkbox" class="radioCheck" name="difficultyCheck" id="c01" value="Yes" onclick="check(this);" />Easy to Say
<input type="checkbox" class="radioCheck" name="difficultyCheck" id="c02" value="No" onclick= "check(this);" />Easy to Read
<input type="checkbox" class="radioCheck" name="difficultyCheck" id="c03" value="No" onclick= "check(this);" checked="true" />All Characters
<input type="range" min="1" max="50" value="10" class="slider" id="myRange">
Length: <span id="demo"></span>
<!-- function to ensure that only one checkbox is checked at a time -->
<script>
function check(input)
{
var checkboxes = document.getElementsByClassName("radioCheck");
for(var i = 0; i < checkboxes.length; i++)
{
//uncheck all
if(checkboxes[i].checked == true)
{
checkboxes[i].checked = false;
}
}
//set checked of clicked object
if(input.checked == true)
{
input.checked = false;
}
else
{
input.checked = true;
}
}
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function() {
output.innerHTML = this.value;
}
</script>
<span id="StrengthDisp" class="badge displayBadge"></span>
</div>
<div class="user-input">
<button type="button" id="submitBtn" name="submitBtn" class="registeration-btn">Register Account</button>
</div>
<div class="login-continer">
<p>Already have an account? <a href="login.html">Log In here!</a></p>
</div>
</div>
</form>
</div>
</body>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.6.0/firebase-app.js";
import { getAuth,createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/10.6.0/firebase-auth.js";
import { getDatabase, set, ref} from "https://www.gstatic.com/firebasejs/10.6.0/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAaJ0fhXXd_WEuTwUTQJpa211weqA7ZQ6w",
authDomain: "term-project-476.firebaseapp.com",
projectId: "term-project-476",
storageBucket: "term-project-476.appspot.com",
messagingSenderId: "276408407460",
appId: "1:276408407460:web:b05ec30e174fb0c3441d31"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
//initialize user authantication
const auth = getAuth(app);
//intilize database
const database = getDatabase(app);
//code author: Zeinab Alrubaiee
//-------------Password Generator Segment-------------
//Builder
class PasswordBuilder {
setLength(length) {
}
includeUppercase() {
}
includeLowercase() {
}
includeNumbers() {
}
includeSpecialCharacters() {
}
GetResult() {}
}
//Concrete Builders
//Easy only incorporates uppercase and lower case letters
class Easy extends PasswordBuilder {
password = new Password;
setLength(length) {
this.password.length = length;
}
includeUppercase() {
this.password.includeUppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
includeLowercase() {
this.password.includeLowercase = "abcdefghijklmnopqrstuvwxyz";
}
includeNumbers() {
this.password.includeNumbers = "";
}
includeSpecialCharacters() {
this.password.includeSpecialCharacters = "";
}
GetResult() {
return this.password;
}
}
//Medium includes uppercase and lower case letters with numbers
class Medium extends PasswordBuilder {
password = new Password;
setLength(length) {
this.password.length = length;
}
includeUppercase() {
this.password.includeUppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
includeLowercase() {
this.password.includeLowercase = "abcdefghijklmnopqrstuvwxyz";
}
includeNumbers() {
this.password.includeNumbers = "0123456789";
}
includeSpecialCharacters() {
this.password.includeSpecialCharacters = "";
}
GetResult() {
return this.password;
}
}
//Hard includes upper and lower case letters, numbers, and special characters
class Hard extends PasswordBuilder {
password = new Password;
setLength(length) {
this.password.length = length;
}
includeUppercase() {
this.password.includeUppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
includeLowercase() {
this.password.includeLowercase = "abcdefghijklmnopqrstuvwxyz";
}
includeNumbers() {
this.password.includeNumbers = "0123456789";
}
includeSpecialCharacters() {
this.password.includeSpecialCharacters = "!@#$%^&*()-_+=<>?";
}
GetResult() {
return this.password;
}
}
// Product
class Password {
length;
includeUppercase;
includeLowercase;
includeNumbers;
includeSpecialCharacters;
show() {
let password = "";
let charset = this.includeUppercase + this.includeLowercase + this.includeNumbers + this.includeSpecialCharacters;
for (let i = 0; i < this.length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset.charAt(randomIndex);
}
return password;
}
}
//Director
class PasswordGenerator {
generate(passwordInstance, length) {
let pass = new Hard();
pass = passwordInstance;
pass.setLength(length);
pass.includeUppercase();
pass.includeLowercase();
pass.includeNumbers();
pass.includeSpecialCharacters();
}
}
const submitBtn = document.getElementById('submitBtn');
const generatePasswordBtn = document.getElementById('generatePasswordBtn');
const passwordInput = document.getElementById('password');
generatePasswordBtn.addEventListener('click', () => {
// Create PasswordGenerator and Password Builders that is dependent on difficulty
let generator = new PasswordGenerator();
let pass = new Hard();
let length = document.getElementById('demo').innerHTML;
if (document.getElementById('c01').checked) {
pass = new Easy();
}
else if (document.getElementById('c02').checked) {
pass = new Medium();
}
else if (document.getElementById('c03').checked) {
pass = new Hard();
}
console.log(length);
generator.generate(pass, length);
let passwordComplete = pass.GetResult();
passwordInput.value = passwordComplete.show();
//The badge is hidden by default, so we show it
strengthBadge.style.display= 'block';
clearTimeout(timeout);
//We then call the StrengChecker function as a callback then pass the typed password to it
timeout = setTimeout(() => StrengthChecker(password.value), 500);
//In case a user clears the text, the badge is hidden again
if(password.value.length !== 0){
strengthBadge.style.display != 'block';
} else{
strengthBadge.style.display = 'none';
}
});
//code author: Shahd Mustafa
//event listener for register button
submitBtn.addEventListener('click', (e) =>{
//retreiving input feilds
var email = document.getElementById('email').value;
var username = document.getElementById('username').value;
var master_password = document.getElementById('password').value;
var question1 = document.getElementById('questions-1').value;
var question2 = document.getElementById('questions-2').value;
var question3 = document.getElementById('questions-3').value;
//create account using firebase auth
createUserWithEmailAndPassword(auth, email, username)
.then((userCredential) => {
// Signed up with user id
const user = userCredential.user;
set(ref(database,'Users/' + user.uid), {
//pushing user data to the database
email: email,
username: username,
master_password:master_password,
question_one: question1,
question_two: question2,
question_three: question3,
})
.then(() =>{
//account creation sucess
alert('User created!');
window.location.href = "login.html";
//user was created
})
.catch((error) => {
alert(errorMessage);
//error in creating user
});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
alert(errorMessage)
});
})
//------------------------Password Strength Checker--------------------------------------------------
// timeout before a callback is called
let timeout;
// traversing the DOM and getting the input and span using their IDs
let password = document.getElementById('password');
let strengthBadge = document.getElementById('StrengthDisp');
// The strong and weak password Regex pattern checker
let strongPassword = new RegExp('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{8,})');
let mediumPassword = new RegExp('((?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9]))');
let okayPassword = new RegExp('((?=.*[a-z])(?=.*[A-Z]))');
function StrengthChecker(PasswordParameter) {
// We then change the badge's color and text based on the password strength
if(strongPassword.test(PasswordParameter)) {
strengthBadge.style.backgroundColor = "green";
strengthBadge.textContent = 'Strong';
} else if(mediumPassword.test(PasswordParameter)){
strengthBadge.style.backgroundColor = 'blue';
strengthBadge.textContent = 'Medium';
} else if(okayPassword.test(PasswordParameter)) {
strengthBadge.style.backgroundColor = 'yellow';
strengthBadge.textContent = 'Acceptable';
} else {
strengthBadge.style.backgroundColor = 'red';
strengthBadge.textContent = 'Weak';
}
}
// Adding an input event listener when a user types to the password input
password.addEventListener("input", () => {
//The badge is hidden by default, so we show it
strengthBadge.style.display= 'block';
clearTimeout(timeout);
//We then call the StrengChecker function as a callback then pass the typed password to it
timeout = setTimeout(() => StrengthChecker(password.value), 500);
//In case a user clears the text, the badge is hidden again
if(password.value.length !== 0){
strengthBadge.style.display != 'block';
} else{
strengthBadge.style.display = 'none';
}
});
</script>
</html>