Documentation Index
Fetch the complete documentation index at: https://mintlify.com/obando1998/Proyecto_UCP/llms.txt
Use this file to discover all available pages before exploring further.
Overview
DevolutionSync uses two complementary models for user management:UsuarioModel- Handles user creation, validation, and listingAuthModel- Handles authentication and credential verification
usuarios database table, which stores user credentials and role information.
Database Table: usuarios
Key Responsibilities:
- User registration and validation
- Authentication and login
- Role-based access control (GRADO system)
- User listing for administration
UsuarioModel
Constructor
Conexion::Conectar().
existeUsuario()
Username to check for existence
bool - true if username exists, false otherwise
guardar()
Username for login (must be unique)
User password (should be hashed before calling this method)
Full name or display name of the user
User role/permission level:
1= Administrator (full access)2= Auxiliary (can register returns)3= Consultation (read-only access)
bool - true on successful insertion, false on failure
listarTodos()
array - Array of associative arrays with user information
Username (login identifier)
User’s full name or display name
User role: 1 (Admin), 2 (Auxiliary), 3 (Consultation)
The query intentionally excludes the
PAS field to prevent accidental password exposure. Passwords should never be retrieved or displayed in user listing interfaces.AuthModel
Constructor
Conexion::Conectar().
buscarUsuario()
Username to authenticate
array|false - Associative array with user data, or false if user not found
Username (matches search parameter)
Hashed password (use with
password_verify())User role: 1 (Admin), 2 (Auxiliary), 3 (Consultation)
User’s full name or display name
Database Schema
Table:usuarios
| Column | Type | Description | Constraints |
|---|---|---|---|
USR | VARCHAR(50) | Username for login | PRIMARY KEY, UNIQUE |
PAS | VARCHAR(255) | Hashed password (bcrypt) | NOT NULL |
NOMBRE | VARCHAR(100) | Full name or display name | NOT NULL |
GRADO | INT | Role/permission level | NOT NULL, CHECK (1-3) |
GRADO Values
TheGRADO field implements role-based access control:
| GRADO | Role Name | Permissions |
|---|---|---|
| 1 | Administrador | Full system access: approve/reject returns, manage users, view all statistics |
| 2 | Auxiliar | Register returns, upload evidence, view own submissions |
| 3 | Consulta | Read-only access: view return history, view statistics (no modifications) |
Implementing Custom Roles
Implementing Custom Roles
To extend the role system beyond three levels:
- Add new GRADO values (e.g., 4 = Warehouse Manager, 5 = Finance)
- Update authorization middleware to check specific permissions
- Create permission mapping:
Password Security Best Practices
Hashing Passwords
Verifying Passwords
Password Requirements
Complete Authentication Flow
Related Models
- DevolucionModel - Uses
usuario_creadorandusuario_revisorfields that reference usuarios - ProductoModel - Products accessed by authenticated users
Security Checklist
Production Security Requirements:
- All passwords hashed with
password_hash(PASSWORD_BCRYPT) - Login form uses HTTPS (SSL/TLS certificate installed)
- Session cookies have
httponlyandsecureflags - Rate limiting implemented on login endpoint
- Failed login attempts logged for security monitoring
- Session timeout configured (recommended: 30 minutes)
- Password complexity requirements enforced
- SQL injection prevented via prepared statements (already implemented)
- XSS protection via output escaping (
htmlspecialchars()) - CSRF tokens implemented on all forms