A production-ready implementation of client-side lock screen and console manager features for React applications. Built with Vite, React Router, and CSS Modules.
- Password Protection: SHA1-hashed password authentication
- Configurable Expiry: Set authentication duration or disable expiry
- localStorage Persistence: Stay logged in across sessions
- Beautiful UI: Gradient design with smooth animations
- Responsive: Works on all device sizes
- Toggle Console Logs: Enable/disable console.log() via localStorage
- Cross-Tab Sync: State synchronized across all browser tabs
- Floating Action Button: Easy access with purple/green status indicator
- Multiple Methods: Intercepts log, warn, error, info, debug
- Developer Friendly: Pro tips and clear status messages
- Scoped Styles: No global namespace pollution
- Maintainable: Clean, organized stylesheets
- Modern: Automatic class name generation
- Node.js 16.x or higher
- npm or yarn
-
Install dependencies:
npm install
-
Start development server:
npm run dev
-
Build for production:
npm run build
-
Preview production build:
npm run preview
- Password:
admin123
-
Lock Screen:
- Click "Logout" button to return to lock screen
- Enter password to unlock
- Authentication persists across page refreshes
-
Console Manager:
- Look for purple/green FAB button in bottom-right corner
- Click to open console manager panel
- Toggle "Enable Console Logs" to control console.log() visibility
- Test with the "Test Console Logs" button on Home page
Edit src/features/lock-screen/config.js:
export const lockScreenConfig = {
// SHA1 hash of 'admin123' (change this!)
passwordHash: 'f865b53623b121fd34ee5426c792e5c33af8c227',
// Expiry time in milliseconds (0 = no expiry)
expiryTime: 0, // or 3600000 for 1 hour
// localStorage key for auth token
storageKey: 'auth_token',
// UI messages
messages: {
title: 'Enter Password',
placeholder: 'Password',
buttonText: 'Unlock',
errorMessage: 'Invalid password. Please try again.',
successMessage: 'Access granted!'
}
};To generate a new password hash:
import { sha1 } from './features/lock-screen/lockScreenService';
const hash = await sha1('your-new-password');
console.log(hash); // Copy this to config.jsEdit src/features/console-manager/config.js:
export const consoleManagerConfig = {
// localStorage key
storageKey: 'enableLog',
// Value to enable console
enableValue: 'ON',
// Default state (false = disabled by default)
defaultEnabled: false,
// Console methods to intercept
interceptMethods: ['log', 'warn', 'error', 'info', 'debug'],
// Show warning when console is disabled
showDisabledWarning: true
};src/
├── features/
│ ├── lock-screen/
│ │ ├── config.js # Lock screen configuration
│ │ ├── lockScreenService.js # Authentication logic
│ │ ├── useLockScreen.js # React hook
│ │ ├── LockScreen.jsx # UI component
│ │ ├── LockScreen.module.css # Scoped styles
│ │ └── index.js # Public exports
│ │
│ └── console-manager/
│ ├── config.js # Console manager configuration
│ ├── consoleManagerService.js # Console interception logic
│ ├── useConsoleManager.js # React hook
│ ├── ConsoleManager.jsx # UI component
│ ├── ConsoleManager.module.css # Scoped styles
│ └── index.js # Public exports
│
├── pages/
│ ├── Home.jsx # Home page component
│ ├── Home.module.css # Home page styles
│ ├── About.jsx # About page component
│ └── About.module.css # About page styles
│
├── App.jsx # Main app with routing
├── main.jsx # Entry point
└── index.css # Global styles
Both features are designed to be portable. To use them in your own projects:
cp -r src/features/lock-screen your-project/src/features/
cp -r src/features/console-manager your-project/src/features/main.jsx:
import { initializeConsoleManager } from './features/console-manager';
// Initialize before rendering
initializeConsoleManager();
ReactDOM.createRoot(document.getElementById('root')).render(
<App />
);App.jsx:
import { LockScreen, useLockScreen } from './features/lock-screen';
import { ConsoleManager } from './features/console-manager';
function App() {
const { authenticated } = useLockScreen();
return authenticated ? (
<>
<ConsoleManager />
<YourAppRoutes />
</>
) : (
<LockScreen />
);
}- Update
passwordHashinlock-screen/config.js - Adjust
defaultEnabledinconsole-manager/config.js - Customize UI messages and settings as needed
React hook that provides authentication state.
Returns:
authenticated(boolean): Current authentication statuscheckAuth(function): Function to manually check authentication
Example:
const { authenticated } = useLockScreen();Functions for authentication management.
Methods:
sha1(text): Generate SHA1 hash (async)validatePassword(inputPassword): Validate password (async)storeAuthToken(): Store authentication tokenisAuthenticated(): Check if user is authenticatedclearAuthToken(): Clear authentication (logout)getRemainingTime(): Get remaining auth time in ms
Example:
import { clearAuthToken } from './features/lock-screen';
function LogoutButton() {
const handleLogout = () => {
clearAuthToken();
};
return <button onClick={handleLogout}>Logout</button>;
}React hook for console state management.
Returns:
enabled(boolean): Current console stateisConsoleEnabled(function): Function to check console state
Example:
const { enabled } = useConsoleManager();Functions for console management.
Methods:
initializeConsoleManager(): Initialize console interceptionisConsoleEnabled(): Check if console is enabledenableConsole(): Enable console logsdisableConsole(): Disable console logstoggleConsole(): Toggle console statesubscribeToConsoleState(callback): Subscribe to state changesforceRestoreConsole(): Restore original console methods
Example:
import { toggleConsole } from './features/console-manager';
function DebugButton() {
return <button onClick={toggleConsole}>Toggle Logs</button>;
}- Client-Side Only: This lock screen is NOT secure for production use with sensitive data
- SHA1 Hashing: Used for demonstration; consider stronger algorithms for real applications
- localStorage: Can be accessed/modified via browser DevTools
- Use Case: Best for internal tools, demos, or basic access control
- Modern browsers with ES6+ support
- Web Crypto API required for password hashing
- localStorage required for persistence
- Lightweight: ~30KB total (unminified)
- No external dependencies beyond React and React Router
- CSS Modules ensure optimal CSS delivery
- Open Console Manager panel (purple/green FAB button)
- Click "Enable Console Logs"
- Refresh the page
- Check localStorage:
enableLogshould beON
- Clear localStorage:
localStorage.removeItem('auth_token') - Refresh the page
- You should see the lock screen
- Ensure CSS Modules are properly imported:
import styles from './Component.module.css' - Use className with styles object:
className={styles.className} - Check Vite config includes CSS Modules support
MIT License - Feel free to use in your projects!
This is a demonstration project, but feel free to fork and customize for your needs!