🔐 Lab 4: Secure Data Storage

ทดสอบการจัดเก็บข้อมูลอย่างปลอดภัยและการจัดการ Session

📋 Security Implementation

✅ Secure Password Hashing (Simulated)

async function hashPassword(password) {
    // Using Web Crypto API (simplified simulation)
    const encoder = new TextEncoder();
    const data = encoder.encode(password + 'salt123');
    const hashBuffer = await crypto.subtle.digest('SHA-256', data);
    const hashArray = Array.from(new Uint8Array(hashBuffer));
    return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}

✅ Secure Session Management

function createSecureSession(userId) {
    const sessionData = {
        userId: userId,
        timestamp: Date.now(),
        token: generateSecureToken()
    };
    
    // Store in secure httpOnly cookie (simulated)
    return sessionData;
}

🔒 ทดสอบ Secure Storage:

🔑 Password Hashing Test

Enter a password and click "Hash Password" to see the hashed result...

👤 Session Management Test

Enter a user ID and click "Create Session" to generate session data...

🔍 Data Storage Simulation

Enter JSON data and click "Store Data Securely" to see encryption simulation...

📊 Current Session Status

No active session

🛡️ Security Features Demonstrated

  • Password Hashing: SHA-256 with salt for secure password storage
  • Session Management: Secure token generation and session tracking
  • Data Encryption: Simulated encryption for sensitive data storage
  • Secure Cookies: httpOnly cookie simulation for session storage
  • Token Generation: Cryptographically secure random tokens