Overview
Simple Invoice implements a secure user management system with PHP session-based authentication, password hashing using PHP’s built-inpassword_verify() function, and comprehensive CRUD operations for managing system users.
Authentication System
Login Class
The authentication system is built around theLogin class located in classes/Login.php:
classes/Login.php
Password Verification
The system uses PHP 5.5’spassword_verify() function for secure password checking:
classes/Login.php
Passwords are stored as hashed values using PHP’s
password_hash() function, which uses the bcrypt algorithm by default.Session Management
Login Process
The login method performs the following steps:- Validate Input: Check that username and password fields are not empty
- Database Query: Search for user by username or email
- Password Verification: Use
password_verify()to check the submitted password against the stored hash - Session Creation: Store user data in PHP session variables
classes/Login.php
Session Checking
All protected pages check login status:usuarios.php
Logout Process
The logout method clears all session data:classes/Login.php
User CRUD Operations
User Database Schema
Theusers table structure from simple_invoice.sql:
User Interface
The user management page (usuarios.php) provides:
- Search functionality: Filter users by name
- Add new user: Modal dialog for user creation
- Edit user: Update user information
- Change password: Separate password update function
AJAX Operations
User operations are handled via AJAX for a smooth user experience:Creating a New User
usuarios.php
Editing a User
usuarios.php
Changing Password
usuarios.php
Security Features
Password Hashing
Uses PHP’s
password_verify() and bcrypt algorithm for secure password storageSQL Injection Protection
Employs
mysqli_real_escape_string() to sanitize user inputsSession Management
PHP sessions track authenticated users across requests
Access Control
All protected pages verify login status before rendering
User Workflow
Related Files
classes/Login.php- Main authentication classusuarios.php- User management interfaceajax/nuevo_usuario.php- Create new user endpointajax/editar_usuario.php- Update user endpointajax/editar_password.php- Change password endpointjs/usuarios.js- Client-side user management logic
The default admin credentials are:
- Username: admin
- Password: (hashed with bcrypt)
- Email: [email protected]
