-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChateOtp.html
More file actions
676 lines (602 loc) · 28.7 KB
/
ChateOtp.html
File metadata and controls
676 lines (602 loc) · 28.7 KB
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Chat App</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<style>
/* General Styles */
body {
background: linear-gradient(135deg, #667eea, #764ba2); /* Gradient background */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.card {
border-radius: 15px; /* Rounded corners */
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); /* Soft shadow */
background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white */
width: 100%;
max-width: 400px;
padding: 2rem;
margin: 1rem;
}
.card h2 {
color: #333; /* Dark text for headings */
margin-bottom: 1.5rem;
text-align: center;
}
.form-control {
border-radius: 25px; /* Rounded input fields */
padding: 10px 20px;
border: 1px solid #ddd; /* Light border */
margin-bottom: 1rem;
}
.form-control:focus {
border-color: #667eea; /* Highlight border on focus */
box-shadow: 0 0 5px rgba(102, 126, 234, 0.5); /* Focus shadow */
}
.btn-primary, .btn-success {
border-radius: 25px; /* Rounded buttons */
padding: 10px 20px;
width: 100%;
font-size: 1rem;
font-weight: bold;
transition: background-color 0.3s ease;
}
.btn-primary {
background-color: #667eea; /* Primary button color */
border: none;
}
.btn-primary:hover {
background-color: #5a6fd1; /* Darker on hover */
}
.btn-success {
background-color: #28a745; /* Success button color */
border: none;
}
.btn-success:hover {
background-color: #218838; /* Darker on hover */
}
.text-center a {
color: #667eea; /* Link color */
text-decoration: none;
}
.text-center a:hover {
text-decoration: underline; /* Underline on hover */
}
/* Chat Container Styles */
#chat-container {
max-width: 100%; /* Full width */
margin: 0; /* Remove margin */
padding: 0;
height: 100vh; /* Full height */
}
#chat-messages {
height: calc(100vh - 120px); /* Responsive height */
overflow-y: auto;
padding: 15px 15px 80px; /* Add padding at the bottom to avoid input box overlap */
background-color: #ece5dd; /* WhatsApp chat background */
scroll-behavior: smooth;
position: relative;
}
.message {
padding: 8px 12px;
margin: 5px 0;
border-radius: 8px;
max-width: 70%;
word-wrap: break-word;
position: relative;
}
.user-message {
background-color: #dcf8c6; /* WhatsApp user message color */
margin-left: auto;
text-align: right;
}
.other-message {
background-color: #fff; /* WhatsApp other message color */
margin-right: auto;
text-align: left;
}
.message-time {
font-size: 0.75rem;
color: #666;
margin-top: 4px;
display: block;
}
.message-username {
font-size: 0.8rem;
font-weight: bold;
color: #333;
margin-bottom: 4px;
}
.input-group {
background-color: #fff;
padding: 10px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
border-top: 1px solid #ddd; /* Add a border at the top */
}
#message-input {
border: none;
border-radius: 25px;
padding: 10px 20px;
background-color: #f1f1f1;
width: calc(100% - 100px); /* Responsive input width */
}
#send-btn {
border: none;
border-radius: 50%;
background-color: #25d366; /* WhatsApp send button color */
color: white;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
#send-btn:disabled {
background-color: #ccc; /* Disabled button color */
cursor: not-allowed;
}
#send-btn:hover:not(:disabled) {
background-color: #128c7e; /* Darker green on hover */
}
@media (max-width: 768px) {
#chat-messages {
height: calc(100vh - 100px); /* Adjust height for smaller screens */
padding-bottom: 70px; /* Adjust padding for smaller screens */
}
#message-input {
width: calc(100% - 90px); /* Adjust input width for smaller screens */
}
#send-btn {
width: 40px; /* Adjust button width for smaller screens */
}
}
</style>
</head>
<body>
<div class="container-fluid">
<!-- Login Form -->
<div id="login-container" class="card">
<h2>Login</h2>
<input type="email" id="login-email" class="form-control" placeholder="Email">
<input type="password" id="login-password" class="form-control" placeholder="Password">
<button id="login-btn" class="btn btn-primary" onclick="login()">Login</button>
<p class="text-center mt-3">Don't have an account? <a href="#" onclick="showRegister()">Register</a></p>
<p class="text-center mt-2"><a href="#" data-bs-toggle="modal" data-bs-target="#forgotPasswordModal">Forgot Password?</a></p>
</div>
<!-- Register Form -->
<div id="register-container" class="card d-none">
<h2>Register</h2>
<input type="text" id="register-username" class="form-control" placeholder="Username">
<input type="email" id="register-email" class="form-control" placeholder="Email">
<input type="password" id="register-password" class="form-control" placeholder="Password">
<input type="password" id="register-confirm-password" class="form-control" placeholder="Confirm Password">
<div class="input-group mt-2">
<input type="text" id="otp-input" class="form-control" placeholder="Enter OTP" disabled>
<button id="send-otp-btn" class="btn btn-primary" onclick="sendOTP()">Send OTP</button>
</div>
<button id="verify-otp-btn" class="btn btn-success mt-2" onclick="verifyOTP()" disabled>Verify OTP</button>
<button id="register-btn" class="btn btn-success mt-2 d-none" onclick="registerUser()">Register</button>
<p class="text-center mt-3">Already have an account? <a href="#" onclick="showLogin()">Login</a></p>
</div>
<!-- Chat Box -->
<div id="chat-container" class="card p-4 shadow-lg d-none">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2>Live Chat</h2>
<button class="btn btn-danger" onclick="logout()">Logout</button>
</div>
<div id="chat-messages">
<div id="loading-message" class="text-center mt-3">
<p>Please wait, your chat is loading...</p>
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
<div class="input-group">
<input type="text" id="message-input" class="form-control" placeholder="Type a message...">
<button id="send-btn" class="btn" onclick="sendMessage()">
<i class="fas fa-paper-plane"></i> <!-- Send icon -->
</button>
</div>
</div>
</div>
<!-- Loading Modal -->
<div class="modal fade" id="loadingModal" tabindex="-1" aria-labelledby="loadingModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-body text-center">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p class="mt-3">Loading chat, please wait...</p>
</div>
</div>
</div>
</div>
<!-- Forgot Password Modal -->
<div class="modal fade" id="forgotPasswordModal" tabindex="-1" aria-labelledby="forgotPasswordModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="forgotPasswordModalLabel">Forgot Password</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="email" id="forgot-email" class="form-control mb-3" placeholder="Enter your email">
<div class="input-group mb-3">
<input type="text" id="forgot-otp" class="form-control" placeholder="Enter OTP" disabled>
<button id="send-forgot-otp-btn" class="btn btn-primary" onclick="sendForgotOTP()">Send OTP</button>
</div>
<input type="password" id="new-password" class="form-control mb-3" placeholder="New Password" disabled>
<input type="password" id="confirm-new-password" class="form-control mb-3" placeholder="Confirm New Password" disabled>
<button id="reset-password-btn" class="btn btn-success w-100" onclick="resetPassword()" disabled>Reset Password</button>
</div>
</div>
</div>
</div>
<script>
const apiUrl = "https://script.google.com/macros/s/AKfycbxW00Yyo4xcRO2Pu_wbXcpeu6-qjmg9kIametsLITa5-bGo-jXBJY25xHFcqh7hBMXvzg/exec";
let currentUsername = "";
let lastSender = ""; // Track the last sender to hide the username for consecutive messages
let otpCountdownInterval; // Variable to store the countdown interval
let otpCountdownTime = 60; // Countdown time in seconds
let forgotPasswordOTPCountdownInterval; // Variable for forgot password OTP countdown
let forgotPasswordOTPCountdownTime = 60; // Countdown time in seconds
$(document).ready(function() {
// Check if the user is already logged in
const loggedIn = localStorage.getItem("loggedIn");
const username = localStorage.getItem("username");
if (loggedIn === "true" && username) {
currentUsername = username;
$("#login-container").addClass("d-none");
$("#chat-container").removeClass("d-none");
// Show the loading message in the chat box
$("#loading-message").show();
startMessagePolling();
}
});
function showRegister() {
$("#login-container").addClass("d-none");
$("#register-container").removeClass("d-none");
}
function showLogin() {
$("#register-container").addClass("d-none");
$("#login-container").removeClass("d-none");
}
function startOTPCountdown() {
// Clear any existing interval
if (otpCountdownInterval) {
clearInterval(otpCountdownInterval);
}
// Disable the button and set the initial countdown text
$("#send-otp-btn").prop("disabled", true).text(`Resend OTP in ${otpCountdownTime}s`);
// Start the countdown
otpCountdownInterval = setInterval(() => {
otpCountdownTime--; // Decrease the countdown time
if (otpCountdownTime <= 0) {
// Stop the countdown when time is up
clearInterval(otpCountdownInterval);
$("#send-otp-btn").prop("disabled", false).text("Send OTP");
otpCountdownTime = 60; // Reset the countdown time
} else {
// Update the button text with the remaining time
$("#send-otp-btn").text(`Resend OTP in ${otpCountdownTime}s`);
}
}, 1000); // Update every second
}
function startForgotPasswordOTPCountdown() {
// Clear any existing interval
if (forgotPasswordOTPCountdownInterval) {
clearInterval(forgotPasswordOTPCountdownInterval);
}
// Disable the button and set the initial countdown text
$("#send-forgot-otp-btn").prop("disabled", true).text(`Resend OTP in ${forgotPasswordOTPCountdownTime}s`);
// Start the countdown
forgotPasswordOTPCountdownInterval = setInterval(() => {
forgotPasswordOTPCountdownTime--; // Decrease the countdown time
if (forgotPasswordOTPCountdownTime <= 0) {
// Stop the countdown when time is up
clearInterval(forgotPasswordOTPCountdownInterval);
$("#send-forgot-otp-btn").prop("disabled", false).text("Send OTP");
forgotPasswordOTPCountdownTime = 60; // Reset the countdown time
} else {
// Update the button text with the remaining time
$("#send-forgot-otp-btn").text(`Resend OTP in ${forgotPasswordOTPCountdownTime}s`);
}
}, 1000); // Update every second
}
function sendOTP() {
const email = $("#register-email").val().trim().toLowerCase(); // Ensure email is lowercase
const username = $("#register-username").val().trim().toLowerCase(); // Ensure username is lowercase
if (!email || !username) {
alert("Please enter your email and username.");
return;
}
// Validate email format
if (!validateEmail(email)) {
alert("Please enter a valid email address.");
return;
}
// Check if username is available
$("#send-otp-btn").prop("disabled", true).text("Checking username...");
$.post(apiUrl, { action: "checkUsername", username }, function(response) {
if (response.success) {
// Username is available, proceed to send OTP
$("#send-otp-btn").text("Sending OTP...");
$.post(apiUrl, { action: "sendOTP", email }, function(response) {
if (response.success) {
alert("OTP sent to your email.");
$("#otp-input").prop("disabled", false);
$("#verify-otp-btn").prop("disabled", false);
// Start the countdown timer
startOTPCountdown();
} else {
alert("Failed to send OTP: " + response.message);
$("#send-otp-btn").prop("disabled", false).text("Send OTP");
}
}, "json").fail(() => {
alert("Failed to send OTP. Please try again.");
$("#send-otp-btn").prop("disabled", false).text("Send OTP");
});
} else {
alert("Username is already taken. Please choose another username.");
$("#send-otp-btn").prop("disabled", false).text("Send OTP");
}
}, "json").fail(() => {
alert("Failed to check username availability. Please try again.");
$("#send-otp-btn").prop("disabled", false).text("Send OTP");
});
}
function validateEmail(email) {
const re = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
return re.test(email);
}
function verifyOTP() {
const email = $("#register-email").val().trim();
const otp = $("#otp-input").val().trim();
const username = $("#register-username").val().trim();
const password = $("#register-password").val().trim();
const confirmPassword = $("#register-confirm-password").val().trim();
if (!email || !otp || !username || !password || !confirmPassword) {
alert("All fields are required.");
return;
}
if (password !== confirmPassword) {
alert("Password and Confirm Password do not match.");
return;
}
if (!validatePassword(password)) {
showPasswordFormatAlert(); // Show alert for invalid password format
return;
}
$("#verify-otp-btn").prop("disabled", true).text("Verifying OTP...");
$.post(apiUrl, { action: "verifyOTP", email, otp, username, password }, function(response) {
if (response.success) {
alert("OTP verified. Registration successful!");
$("#register-btn").removeClass("d-none");
$("#verify-otp-btn").addClass("d-none");
} else {
alert("OTP verification failed: " + response.message);
}
}, "json").always(() => {
$("#verify-otp-btn").prop("disabled", false).text("Verify OTP");
});
}
function registerUser() {
const username = $("#register-username").val().trim();
const email = $("#register-email").val().trim();
const password = $("#register-password").val().trim();
const confirmPassword = $("#register-confirm-password").val().trim();
if (!username || !email || !password || !confirmPassword) {
alert("All fields are required.");
return;
}
if (password !== confirmPassword) {
alert("Password and Confirm Password do not match.");
return;
}
if (!validatePassword(password)) {
showPasswordFormatAlert(); // Show alert for invalid password format
return;
}
$("#register-btn").prop("disabled", true).text("Registering...");
$.post(apiUrl, { action: "register", username, email, password }, function(response) {
if (response.success) {
alert("Registration successful! Redirecting to login page...");
setTimeout(() => {
showLogin(); // Automatically switch to the login page after 2 seconds
}, 2000);
} else {
alert("Registration failed: " + response.message);
}
}, "json").always(() => {
$("#register-btn").prop("disabled", false).text("Register");
});
}
function login() {
const email = $("#login-email").val().trim();
const password = $("#login-password").val().trim();
if (!email || !password) {
alert("All fields are required!");
return;
}
$("#login-btn").prop("disabled", true).text("Logging in...");
$("#loadingModal").modal("show"); // Show loading modal
$.post(apiUrl, { action: "login", email, password }, function(response) {
if (response.success) {
currentUsername = response.username;
// Store login state in localStorage
localStorage.setItem("loggedIn", "true");
localStorage.setItem("username", currentUsername);
$("#login-container").addClass("d-none");
$("#chat-container").removeClass("d-none");
// Show the loading message in the chat box
$("#loading-message").show();
startMessagePolling();
setTimeout(() => {
$("#loadingModal").modal("hide"); // Hide loading modal after 5 seconds
}, 5000);
} else {
showWrongPasswordAlert(); // Show alert for wrong password
$("#loadingModal").modal("hide"); // Hide loading modal immediately
}
}, "json").always(() => {
$("#login-btn").prop("disabled", false).text("Login");
});
}
function sendMessage() {
const message = $("#message-input").val().trim();
if (!message) return;
// Disable input and send button
$("#message-input").prop("disabled", true);
$("#send-btn").prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i>'); // Show loading spinner
$.post(apiUrl, { action: "sendMessage", username: currentUsername, message }, function() {
// Re-enable input and send button
$("#message-input").prop("disabled", false);
$("#send-btn").prop("disabled", false).html('<i class="fas fa-paper-plane"></i>'); // Re-enable send button
$("#message-input").val(""); // Clear the input field
loadMessages(true); // Force scroll to bottom for sent messages
}).fail(() => {
// Re-enable input and send button on failure
$("#message-input").prop("disabled", false);
$("#send-btn").prop("disabled", false).html('<i class="fas fa-paper-plane"></i>'); // Re-enable send button
alert("Failed to send message. Please try again.");
});
}
function loadMessages(forceScroll = false) {
$.get(apiUrl + "?action=getMessages", function(response) {
if (!response.messages) return;
let chatBox = $("#chat-messages");
let isAtBottom = chatBox[0].scrollHeight - chatBox[0].scrollTop === chatBox[0].clientHeight;
// Hide the loading message
$("#loading-message").hide();
chatBox.empty(); // Clear the chat box before appending new messages
// Append each message to the chat box
response.messages.forEach((msg, index) => {
let msgClass = msg.sender === currentUsername ? "user-message" : "other-message";
let messageText = msg.text.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1" target="_blank">$1</a>');
let messageTime = new Date(msg.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // Use the timestamp from the sheet
// Check if the current sender is the same as the previous sender
let showUsername = msg.sender !== lastSender;
lastSender = msg.sender; // Update the last sender
chatBox.append(`
<div class="message ${msgClass}">
${showUsername ? `<div class="message-username">${msg.sender}</div>` : ''}
<div>${messageText}</div>
<span class="message-time">${messageTime}</span>
</div>
`);
});
// Scroll to bottom if it's a sent message or if the user is already at the bottom
if (forceScroll || isAtBottom) {
scrollToBottom();
}
}, "json").fail(() => {
console.error("Error fetching messages!");
// Show an error message if loading fails
$("#loading-message").html("<p class='text-danger'>Failed to load messages. Please try again.</p>");
});
}
function scrollToBottom() {
let chatBox = $("#chat-messages");
chatBox.scrollTop(chatBox[0].scrollHeight);
}
function startMessagePolling() {
setInterval(() => loadMessages(), 3000); // Poll for new messages every 3 seconds
}
function logout() {
// Clear login state from localStorage
localStorage.removeItem("loggedIn");
localStorage.removeItem("username");
// Reload the page to reset the app
location.reload();
}
// Forgot Password Functions
function sendForgotOTP() {
const email = $("#forgot-email").val().trim();
if (!email) {
alert("Please enter your email.");
return;
}
$("#send-forgot-otp-btn").prop("disabled", true).text("Sending OTP...");
$.post(apiUrl, { action: "sendOTP", email }, function(response) {
if (response.success) {
alert("OTP sent to your email.");
$("#forgot-otp").prop("disabled", false);
$("#reset-password-btn").prop("disabled", false);
$("#new-password").prop("disabled", false);
$("#confirm-new-password").prop("disabled", false);
// Start the countdown timer
startForgotPasswordOTPCountdown();
} else {
alert("Failed to send OTP: " + response.message);
$("#send-forgot-otp-btn").prop("disabled", false).text("Send OTP");
}
}, "json").fail(() => {
alert("Failed to send OTP. Please try again.");
$("#send-forgot-otp-btn").prop("disabled", false).text("Send OTP");
});
}
function resetPassword() {
const email = $("#forgot-email").val().trim();
const otp = $("#forgot-otp").val().trim();
const newPassword = $("#new-password").val().trim();
const confirmNewPassword = $("#confirm-new-password").val().trim();
if (!email || !otp || !newPassword || !confirmNewPassword) {
alert("All fields are required.");
return;
}
if (newPassword !== confirmNewPassword) {
alert("New Password and Confirm New Password do not match.");
return;
}
if (!validatePassword(newPassword)) {
showPasswordFormatAlert(); // Show alert for invalid password format
return;
}
$("#reset-password-btn").prop("disabled", true).text("Resetting Password...");
$.post(apiUrl, { action: "resetPassword", email, otp, newPassword }, function(response) {
if (response.success) {
alert("Password reset successful!");
$("#forgotPasswordModal").modal("hide"); // Close the modal
} else {
alert("Password reset failed: " + response.message);
}
}, "json").always(() => {
$("#reset-password-btn").prop("disabled", false).text("Reset Password");
});
}
// Password validation function
function validatePassword(password) {
// At least 1 special character, 1 number, and minimum 8 characters
const specialChars = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
const numbers = /[0-9]+/;
return password.length >= 8 && specialChars.test(password) && numbers.test(password);
}
// Show alert for invalid password format
function showPasswordFormatAlert() {
alert("Password must contain at least 1 special character, 1 number, and be at least 8 characters long.");
}
// Show alert for wrong password
function showWrongPasswordAlert() {
alert("Your password is wrong. Please enter the correct password.");
}
</script>
</body>
</html>