Overview
User accounts in Pro Stock Tool are stored in theusuarios table within the prostocktool MySQL database. Each account contains essential user information and authentication credentials.
Database Configuration
The system connects to the database using the following configuration (conexion.php:3-8):
The database connection includes automatic error handling that returns HTTP 500 status codes on connection failures.
User Table Structure
Based on the registration implementation, theusuarios table contains the following fields:
Schema
| Column | Data Type | Constraints | Description |
|---|---|---|---|
id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique user identifier |
email | VARCHAR | UNIQUE, NOT NULL | User’s email address |
nombre | VARCHAR(100) | NOT NULL | User’s full name |
identidad | VARCHAR(20) | UNIQUE, NOT NULL | Government-issued ID number |
password | VARCHAR(255) | NOT NULL | BCrypt hashed password |
creado_en | TIMESTAMP | DEFAULT NOW() | Account creation timestamp |
Field Details
- Purpose: Primary identifier for user login
- Validation: Must pass email format validation
- Uniqueness: Each email can only be registered once
- Example:
[email protected]
Nombre (Name)
- Purpose: User’s full name for identification
- Length: 2-100 characters
- Validation: Must contain at least 2 characters
- Example:
Juan David Pérez
Identidad (ID Number)
- Purpose: Government-issued identification number
- Format: Numeric only, 6-20 digits
- Uniqueness: Each ID can only be registered once
- Example:
1067623487
Password
- Storage: BCrypt hashed (never plain text)
- Minimum Length: 6 characters (enforced at registration)
- Algorithm:
PASSWORD_BCRYPT - Salt: Automatically generated by PHP’s
password_hash()
BCrypt automatically handles salt generation and produces hashes approximately 60 characters long.
Creado_en (Created At)
- Purpose: Timestamp of account creation
- Type: MySQL TIMESTAMP
- Value: Auto-populated using
NOW()function - Format: YYYY-MM-DD HH:MM:SS
Account Creation Process
When a new user registers, the following SQL query is executed (registro.php:51-52):
Data Sanitization
All user inputs are sanitized before database insertion to prevent SQL injection:Duplicate Prevention
Before creating a new account, the system checks for existing records (registro.php:42-45):
User Authentication Flow
Login Credentials
Users authenticate using:- Email address - Entered in the email field
- Password - Verified against BCrypt hash
Inicio-Sesion.html:47-50):
Password Verification
While the login controller isn’t in the provided source, password verification typically uses:PHP’s
password_verify() function is the complement to password_hash() and properly handles BCrypt comparison.Security Considerations
Password Security
BCrypt Hashing
Industry-standard algorithm designed to be computationally expensive for brute-force attacks.
Automatic Salting
Each password hash includes a unique salt, preventing rainbow table attacks.
No Plain Text
Passwords are never stored in readable format, only as irreversible hashes.
Minimum Length
6-character minimum enforced on both client and server sides.
Data Protection
- Input Sanitization
- SQL Injection Prevention
- Connection Error Handling
All user inputs are escaped using
real_escape_string() before database queries:Account Data Flow
Registration Flow
Authentication Flow
API Endpoints
Registration Endpoint
URL:/database/registro.phpMethod: POST
Content-Type: application/json Request Body:
CORS Headers
The registration endpoint includes CORS headers for cross-origin requests (registro.php:2-5):
User Account Lifecycle
Validation
System validates all inputs on client and server, checks for duplicates, and creates account.
Common Queries
Check if Email Exists
Check if ID Number Exists
Retrieve User by Email
Count Total Users
Best Practices
Password Management
Password Management
- Always hash passwords using BCrypt or stronger algorithms
- Never log or display passwords in plain text
- Enforce minimum password length (6+ characters)
- Consider implementing password strength requirements
- Use HTTPS to encrypt passwords in transit
Data Validation
Data Validation
- Validate on both client and server sides
- Use prepared statements or proper escaping for SQL queries
- Sanitize all user inputs before database operations
- Implement proper error handling and user feedback
Uniqueness Enforcement
Uniqueness Enforcement
- Create unique indexes on email and identidad columns
- Check for duplicates before insertion
- Provide clear error messages when duplicates are detected
- Consider implementing email verification
Security Headers
Security Headers
- Implement proper CORS policies
- Use Content Security Policy (CSP) headers
- Enable HTTPS in production
- Restrict database access to application user only
Error Handling
The account system implements comprehensive error handling:Registration Errors
| Error Message | Cause | Resolution |
|---|---|---|
| Método no permitido | Non-POST request | Use POST method |
| Datos inválidos | Invalid JSON | Check request format |
| Email inválido | Invalid email format | Use valid email address |
| Nombre inválido | Name too short/long | Use 2-100 characters |
| Identidad inválida | Invalid ID format | Use 6-20 digits only |
| Contraseña muy corta | Password < 6 chars | Use 6+ character password |
| Email o Identidad ya registrados | Duplicate credentials | Use different email/ID |
| Error al registrar | Database error | Check server logs |
| Error del servidor | Exception thrown | Contact administrator |
Connection Errors
Database Connection Management
The connection is properly closed after each request (registro.php:61):
Properly closing database connections prevents resource leaks and ensures optimal server performance.
Next Steps
Authentication
Learn about the login system
Registration
Understand the signup process
Database Setup
Configure the database