@@ -998,6 +998,15 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
998998 localStorage . setItem ( AUTH_USERS_KEY , JSON . stringify ( users ) ) ;
999999 }
10001000
1001+ // 密碼雜湊函數(使用 Web Crypto API)
1002+ async function hashPassword ( password ) {
1003+ const encoder = new TextEncoder ( ) ;
1004+ const data = encoder . encode ( password ) ;
1005+ const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , data ) ;
1006+ const hashArray = Array . from ( new Uint8Array ( hashBuffer ) ) ;
1007+ return hashArray . map ( b => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
1008+ }
1009+
10011010 function getCurrentUserEmail ( ) {
10021011 return localStorage . getItem ( AUTH_CURRENT_USER_KEY ) ;
10031012 }
@@ -1215,7 +1224,8 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
12151224 return ;
12161225 }
12171226 const users = getStoredUsers ( ) ;
1218- const match = users . find ( user => user . email === email && user . password === password ) ;
1227+ const hashedPassword = await hashPassword ( password ) ;
1228+ const match = users . find ( user => user . email === email && user . passwordHash === hashedPassword ) ;
12191229 if ( ! match ) {
12201230 setAuthError ( 'auth-login-error' , '帳號或密碼錯誤,請重新輸入。' ) ;
12211231 return ;
@@ -1266,7 +1276,8 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
12661276 setAuthError ( 'auth-register-error' , '此郵箱已註冊,請直接登入。' ) ;
12671277 return ;
12681278 }
1269- users . push ( { email, password } ) ;
1279+ const passwordHash = await hashPassword ( password ) ;
1280+ users . push ( { email, passwordHash } ) ;
12701281 saveStoredUsers ( users ) ;
12711282 setCurrentUserEmail ( email ) ;
12721283 setCachedAuthEmail ( email ) ;
@@ -1353,17 +1364,6 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
13531364 switchTab ( initialTab ) ;
13541365 }
13551366
1356- function isPlaceholderFirebaseConfig ( cfg ) {
1357- return ! cfg . apiKey || cfg . apiKey . startsWith ( 'YOUR_' ) || ! cfg . projectId || cfg . projectId . includes ( 'YOUR_PROJECT_ID' ) ;
1358- }
1359- function setAllRecords ( newRecords ) {
1360- window . allRecords = ( newRecords || [ ] ) . sort ( ( a , b ) => new Date ( b . date ) - new Date ( a . date ) ) ;
1361- if ( window . renderRecordsTable ) window . renderRecordsTable ( ) ;
1362- if ( window . renderAdminTable ) window . renderAdminTable ( ) ;
1363- renderAnalyticsYearOptions ( ) ;
1364- if ( window . updateCharts ) window . updateCharts ( ) ;
1365- }
1366-
13671367 function parseSalaryGrowth ( value ) {
13681368 if ( value === undefined || value === null ) return null ;
13691369 const num = parseFloat ( String ( value ) . replace ( '%' , '' ) . trim ( ) ) ;
@@ -1653,16 +1653,6 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
16531653 renderSalaryGrowthChart ( stats ) ;
16541654 } ;
16551655
1656- function isPlaceholderFirebaseConfig ( cfg ) {
1657- return ! cfg . apiKey || cfg . apiKey . startsWith ( 'YOUR_' ) || ! cfg . projectId || cfg . projectId . includes ( 'YOUR_PROJECT_ID' ) ;
1658- }
1659- function setAllRecords ( newRecords ) {
1660- window . allRecords = ( newRecords || [ ] ) . sort ( ( a , b ) => new Date ( b . date ) - new Date ( a . date ) ) ;
1661- if ( window . renderRecordsTable ) window . renderRecordsTable ( ) ;
1662- if ( window . renderAdminTable ) window . renderAdminTable ( ) ;
1663- if ( window . updateCharts ) window . updateCharts ( ) ;
1664- }
1665-
16661656 // Google Drive (可透過 __google_drive_config 覆寫)
16671657 const defaultGoogleDriveConfig = {
16681658 apiKey : 'YOUR_GOOGLE_API_KEY' ,
@@ -1691,6 +1681,7 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
16911681 persistLocalRecords ( window . allRecords ) ;
16921682 if ( window . renderRecordsTable ) window . renderRecordsTable ( ) ;
16931683 if ( window . renderAdminTable ) window . renderAdminTable ( ) ;
1684+ renderAnalyticsYearOptions ( ) ;
16941685 if ( window . updateCharts ) window . updateCharts ( ) ;
16951686 if ( window . updateDraftSelector ) window . updateDraftSelector ( ) ;
16961687 }
@@ -2523,29 +2514,27 @@ <h3 class="text-white font-bold">編輯紀錄</h3>
25232514 import { getAuth , signInAnonymously , onAuthStateChanged , signInWithCustomToken , createUserWithEmailAndPassword , signInWithEmailAndPassword , sendPasswordResetEmail , signOut } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js" ;
25242515 import { getFirestore , collection , addDoc , onSnapshot , doc , updateDoc , deleteDoc , query , orderBy , setDoc } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-firestore.js" ;
25252516
2526- const firebaseConfig = {
2527- apiKey : "AIzaSyAGPH6HKTi8yikT9rG_VhoivwWycM5LO6Y" ,
2528- authDomain : "resignation-system.firebaseapp.com" ,
2529- projectId : "resignation-system" ,
2530- storageBucket : "resignation-system.firebasestorage.app" ,
2531- messagingSenderId : "20779725950" ,
2532- appId : "1:20779725950:web:12a2d3b753d5cf3bc0d42f" ,
2533- measurementId : "G-EH2FBKQTKD"
2534- } ;
2535- // 為了在沒有變數的情況下不報錯,這裡做一個防呆
2536- // 實際部署時請務必填寫上方 config
2537-
2538- // 注意:GitHub Pages 部署時,以下這行必須修改
2539- // const firebaseConfig = JSON.parse(__firebase_config);
2540-
2541- // 在此環境下為了模擬,我們還是會嘗試讀取變數,但會加上 try-catch
2542- let finalConfig = firebaseConfig ;
2517+ // Firebase 配置:優先從環境變數 __firebase_config 讀取
2518+ // 部署時請透過 script 標籤注入:<script>window.__firebase_config = '{"apiKey":"...","projectId":"..."}'; </ script >
2519+ const defaultFirebaseConfig = {
2520+ apiKey: "YOUR_API_KEY",
2521+ authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
2522+ projectId: "YOUR_PROJECT_ID",
2523+ storageBucket: "YOUR_PROJECT_ID.appspot.com",
2524+ messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
2525+ appId: "YOUR_APP_ID"
2526+ };
2527+
2528+ let finalConfig = defaultFirebaseConfig;
25432529 try {
2544- if ( typeof __firebase_config !== 'undefined' ) {
2545- finalConfig = JSON . parse ( __firebase_config ) ;
2530+ if (typeof window.__firebase_config !== 'undefined' && window.__firebase_config) {
2531+ const injectedConfig = typeof window.__firebase_config === 'string'
2532+ ? JSON.parse(window.__firebase_config)
2533+ : window.__firebase_config;
2534+ finalConfig = { ...defaultFirebaseConfig, ...injectedConfig };
25462535 }
25472536 } catch(e) {
2548- console . log ( "Using placeholder config" ) ;
2537+ console.warn("Firebase 配置解析失敗,使用預設值", e );
25492538 }
25502539
25512540 if (isPlaceholderFirebaseConfig(finalConfig)) {
0 commit comments