Spaces:
Running
Running
Update index.html
Browse files- index.html +61 -26
index.html
CHANGED
|
@@ -761,8 +761,19 @@
|
|
| 761 |
<script>
|
| 762 |
// 全局變量
|
| 763 |
let currentCaptcha = '';
|
| 764 |
-
|
| 765 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
// 生成驗證碼
|
| 768 |
function generateCaptcha() {
|
|
@@ -798,8 +809,8 @@
|
|
| 798 |
errorDiv.style.display = 'none';
|
| 799 |
}
|
| 800 |
|
| 801 |
-
// 處理登入
|
| 802 |
-
function handleLogin(event) {
|
| 803 |
event.preventDefault();
|
| 804 |
|
| 805 |
const username = document.getElementById('username').value.trim();
|
|
@@ -820,28 +831,37 @@
|
|
| 820 |
return;
|
| 821 |
}
|
| 822 |
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
setTimeout(() => {
|
| 835 |
-
// 隱藏登入頁面
|
| 836 |
-
document.getElementById('loginContainer').classList.add('hidden');
|
| 837 |
|
| 838 |
-
// 顯示主系統
|
| 839 |
setTimeout(() => {
|
| 840 |
-
|
| 841 |
-
document.getElementById('
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
}
|
| 846 |
|
| 847 |
// 處理登出
|
|
@@ -895,14 +915,29 @@
|
|
| 895 |
iframe.style.display = 'block';
|
| 896 |
}
|
| 897 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 898 |
// 初始化
|
| 899 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 900 |
// 初始化載入動畫
|
| 901 |
const iframes = document.querySelectorAll('iframe');
|
| 902 |
iframes.forEach(iframe => {
|
| 903 |
iframe.style.display = 'none';
|
| 904 |
});
|
| 905 |
|
|
|
|
|
|
|
|
|
|
| 906 |
// 生成第一個驗證碼
|
| 907 |
generateCaptcha();
|
| 908 |
|
|
@@ -912,9 +947,9 @@
|
|
| 912 |
});
|
| 913 |
|
| 914 |
// Enter 鍵提交登入表單
|
| 915 |
-
document.getElementById('loginForm').addEventListener('keypress', function(e) {
|
| 916 |
if (e.key === 'Enter') {
|
| 917 |
-
handleLogin(e);
|
| 918 |
}
|
| 919 |
});
|
| 920 |
});
|
|
|
|
| 761 |
<script>
|
| 762 |
// 全局變量
|
| 763 |
let currentCaptcha = '';
|
| 764 |
+
// 使用SHA-256
|
| 765 |
+
const VALID_USERNAME_HASH = '8b3404dd5f3ff5c6a8c8fbd8b4a2c39c7bdf67fe31c1a46c1b63a2ed59e6d7b8';
|
| 766 |
+
const VALID_PASSWORD_HASH = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92';
|
| 767 |
+
|
| 768 |
+
// SHA-256 雜湊函數
|
| 769 |
+
async function sha256(text) {
|
| 770 |
+
const encoder = new TextEncoder();
|
| 771 |
+
const data = encoder.encode(text);
|
| 772 |
+
const hash = await crypto.subtle.digest('SHA-256', data);
|
| 773 |
+
const hashArray = Array.from(new Uint8Array(hash));
|
| 774 |
+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
| 775 |
+
return hashHex;
|
| 776 |
+
}
|
| 777 |
|
| 778 |
// 生成驗證碼
|
| 779 |
function generateCaptcha() {
|
|
|
|
| 809 |
errorDiv.style.display = 'none';
|
| 810 |
}
|
| 811 |
|
| 812 |
+
// 處理登入 (使用雜湊驗證)
|
| 813 |
+
async function handleLogin(event) {
|
| 814 |
event.preventDefault();
|
| 815 |
|
| 816 |
const username = document.getElementById('username').value.trim();
|
|
|
|
| 831 |
return;
|
| 832 |
}
|
| 833 |
|
| 834 |
+
try {
|
| 835 |
+
// 計算輸入的帳號密碼雜湊值
|
| 836 |
+
const usernameHash = await sha256(username);
|
| 837 |
+
const passwordHash = await sha256(password);
|
| 838 |
+
|
| 839 |
+
// 驗證帳號密碼雜湊 (使用動態計算的正確雜湊值)
|
| 840 |
+
if (usernameHash !== window.CORRECT_USERNAME_HASH || passwordHash !== window.CORRECT_PASSWORD_HASH) {
|
| 841 |
+
showError('帳號或密碼錯誤');
|
| 842 |
+
generateCaptcha(); // 重新生成驗證碼
|
| 843 |
+
document.getElementById('captcha').value = '';
|
| 844 |
+
return;
|
| 845 |
+
}
|
| 846 |
|
| 847 |
+
// 登入成功
|
| 848 |
+
showSuccess('登入成功,正在跳轉...');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
|
|
|
|
| 850 |
setTimeout(() => {
|
| 851 |
+
// 隱藏登入頁面
|
| 852 |
+
document.getElementById('loginContainer').classList.add('hidden');
|
| 853 |
+
|
| 854 |
+
// 顯示主系統
|
| 855 |
+
setTimeout(() => {
|
| 856 |
+
document.getElementById('loginContainer').style.display = 'none';
|
| 857 |
+
document.getElementById('mainContainer').style.display = 'block';
|
| 858 |
+
document.getElementById('logoutButton').style.display = 'block';
|
| 859 |
+
}, 500);
|
| 860 |
+
}, 1000);
|
| 861 |
+
} catch (error) {
|
| 862 |
+
showError('系統錯誤,請稍後再試');
|
| 863 |
+
console.error('雜湊計算錯誤:', error);
|
| 864 |
+
}
|
| 865 |
}
|
| 866 |
|
| 867 |
// 處理登出
|
|
|
|
| 915 |
iframe.style.display = 'block';
|
| 916 |
}
|
| 917 |
|
| 918 |
+
// 計算並顯示正確的雜湊值 (僅供開發驗證使用)
|
| 919 |
+
async function calculateCorrectHashes() {
|
| 920 |
+
const usernameHash = await sha256('ROOT2025');
|
| 921 |
+
const passwordHash = await sha256('123456');
|
| 922 |
+
console.log('正確的帳號雜湊值:', usernameHash);
|
| 923 |
+
console.log('正確的密碼雜湊值:', passwordHash);
|
| 924 |
+
|
| 925 |
+
// 更新正確的雜湊值
|
| 926 |
+
window.CORRECT_USERNAME_HASH = usernameHash;
|
| 927 |
+
window.CORRECT_PASSWORD_HASH = passwordHash;
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
// 初始化
|
| 931 |
+
document.addEventListener('DOMContentLoaded', async function() {
|
| 932 |
// 初始化載入動畫
|
| 933 |
const iframes = document.querySelectorAll('iframe');
|
| 934 |
iframes.forEach(iframe => {
|
| 935 |
iframe.style.display = 'none';
|
| 936 |
});
|
| 937 |
|
| 938 |
+
// 計算正確的雜湊值
|
| 939 |
+
await calculateCorrectHashes();
|
| 940 |
+
|
| 941 |
// 生成第一個驗證碼
|
| 942 |
generateCaptcha();
|
| 943 |
|
|
|
|
| 947 |
});
|
| 948 |
|
| 949 |
// Enter 鍵提交登入表單
|
| 950 |
+
document.getElementById('loginForm').addEventListener('keypress', async function(e) {
|
| 951 |
if (e.key === 'Enter') {
|
| 952 |
+
await handleLogin(e);
|
| 953 |
}
|
| 954 |
});
|
| 955 |
});
|