HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: /var/www/indoadvisory_new/webapp/src/utils/auth.ts
// Authentication utilities
export interface User {
  id: number;
  username: string;
  email: string;
  name: string;
  role: string;
}

export interface Session {
  id: string;
  user_id: number;
  expires_at: string;
}

// Simple session management (in production, use proper JWT or secure sessions)
export function generateSessionId(): string {
  return Math.random().toString(36).substring(2) + Date.now().toString(36);
}

export function isValidSession(session: Session | null): boolean {
  if (!session) return false;
  return new Date(session.expires_at) > new Date();
}

// Simple password validation (in production, use proper hashing like bcrypt)
export function validatePassword(inputPassword: string, storedPassword: string): boolean {
  // For demo purposes, using simple comparison
  // In production, use: await bcrypt.compare(inputPassword, storedPassword)
  return inputPassword === storedPassword;
}

export function hashPassword(password: string): string {
  // For demo purposes, returning plain text
  // In production, use: await bcrypt.hash(password, 10)
  return password;
}

// Check if user is admin
export function isAdmin(user: User | null): boolean {
  return user?.role === 'admin';
}