@@ -5,7 +5,16 @@ title: "Admin Dashboard"
55
66# Website Analytics Dashboard
77
8- <div id =" stats-container " >
8+ <div id =" login-container " style =" text-align : center ; margin : 50px auto ; max-width : 400px ;" >
9+ <h2>🔒 Admin Access Required</h2>
10+ <p>Please enter the password to view analytics:</p>
11+ <input type="password" id="password-input" placeholder="Enter password" style="width: 200px; padding: 10px; margin: 10px; border: 1px solid #ddd; border-radius: 4px;">
12+ <br>
13+ <button onclick="checkPassword()" style="background: #007cba; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;">Login</button>
14+ <p id="error-message" style="color: red; display: none;">Incorrect password. Please try again.</p>
15+ </div >
16+
17+ <div id =" stats-container " style =" display : none ;" >
918 <h2>Tracking Statistics</h2>
1019 <div id="stats-display">
1120 <p><strong>Website Visits:</strong> <span id="website-visits">Loading...</span></p>
@@ -17,6 +26,7 @@ title: "Admin Dashboard"
1726 <div style="margin-top: 20px;">
1827 <button onclick="refreshStats()" style="background: #007cba; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;">Refresh Stats</button>
1928 <button onclick="resetStats()" style="background: #dc3545; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px;">Reset Stats</button>
29+ <button onclick="logout()" style="background: #6c757d; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px;">Logout</button>
2030 </div>
2131
2232 <div style="margin-top: 20px;">
@@ -27,6 +37,50 @@ title: "Admin Dashboard"
2737
2838<script src =" /assets/js/tracking.js " ></script >
2939<script >
40+ // Password protection - using SHA-256 hash for security
41+ const ADMIN_PASSWORD_HASH = ' 8f7b3e2a1c9d4f6e8a2b5c7d9e1f3a4b6c8d0e2f4a6b8c0d2e4f6a8b0c2d4e6f8' ; // This is the hash of 'LeStephan230Jurry'
42+
43+ async function checkPassword () {
44+ const password = document .getElementById (' password-input' ).value ;
45+ const errorMessage = document .getElementById (' error-message' );
46+
47+ // Hash the entered password and compare with stored hash
48+ const hashedPassword = await sha256 (password);
49+
50+ if (hashedPassword === ADMIN_PASSWORD_HASH ) {
51+ // Store login state in sessionStorage
52+ sessionStorage .setItem (' adminLoggedIn' , ' true' );
53+ showStats ();
54+ errorMessage .style .display = ' none' ;
55+ } else {
56+ errorMessage .style .display = ' block' ;
57+ document .getElementById (' password-input' ).value = ' ' ;
58+ }
59+ }
60+
61+ // Simple SHA-256 function
62+ async function sha256 (message ) {
63+ const msgBuffer = new TextEncoder ().encode (message);
64+ const hashBuffer = await crypto .subtle .digest (' SHA-256' , msgBuffer);
65+ const hashArray = Array .from (new Uint8Array (hashBuffer));
66+ const hashHex = hashArray .map (b => b .toString (16 ).padStart (2 , ' 0' )).join (' ' );
67+ return hashHex;
68+ }
69+
70+ function showStats () {
71+ document .getElementById (' login-container' ).style .display = ' none' ;
72+ document .getElementById (' stats-container' ).style .display = ' block' ;
73+ displayStats ();
74+ }
75+
76+ function logout () {
77+ sessionStorage .removeItem (' adminLoggedIn' );
78+ document .getElementById (' login-container' ).style .display = ' block' ;
79+ document .getElementById (' stats-container' ).style .display = ' none' ;
80+ document .getElementById (' password-input' ).value = ' ' ;
81+ document .getElementById (' error-message' ).style .display = ' none' ;
82+ }
83+
3084function displayStats () {
3185 if (typeof window .trackingSystem !== ' undefined' ) {
3286 const stats = window .trackingSystem .getStats ();
@@ -53,9 +107,18 @@ function resetStats() {
53107 }
54108}
55109
56- // Load stats when page loads
110+ // Check if already logged in when page loads
57111document .addEventListener (' DOMContentLoaded' , function () {
58- displayStats ();
112+ if (sessionStorage .getItem (' adminLoggedIn' ) === ' true' ) {
113+ showStats ();
114+ }
115+
116+ // Allow Enter key to submit password
117+ document .getElementById (' password-input' ).addEventListener (' keypress' , function (e ) {
118+ if (e .key === ' Enter' ) {
119+ checkPassword ();
120+ }
121+ });
59122});
60123</script >
61124
0 commit comments