Overview
The User Management module allows administrators to create, update, and manage user accounts for the TechCore Mini ERP system. Each user is assigned to a role that determines their access permissions throughout the application.User Entity
Users are stored in theusers table with the following properties:
Unique identifier for the user (auto-incremented)
User code (max 10 characters). Must be unique across all users.
Full name of the user (max 200 characters)
Login username (max 100 characters). Must be unique across all users.
Password hash for authentication (stored securely)
Contact phone number (max 15 characters)
Foreign key reference to the user’s assigned role
Email address (max 200 characters)
Timestamp when the user account was created (defaults to current date/time)
Database Schema
Indexes
The users table includes optimized indexes for performance:- IDX_users_code: Unique index on
codefield for fast lookups - IDX_users_idrol: Index on
idrolfor efficient role-based queries - IDX_users_email: Index on
emailfor email-based searches
Relationships
Role Assignment
Each user must be assigned to a role via the
Idrol property, which references the rol table.Sales Tracking
Users can be associated with sales records (
Venta) to track which user processed each sale.Purchase Orders
Users are linked to purchase orders (
Compra) to maintain an audit trail of who created each purchase.User Operations
Creating a New User
When creating a new user account:- Assign a unique
Code(max 10 characters) - Provide a unique
Usernamefor login - Hash the password before storing in
Pwdfield - Assign an
Idrolthat corresponds to an existing role - Optionally provide contact information (
Phone,Email)
User Authentication
Users authenticate using theirUsername and Pwd credentials. The system validates:
- Username exists in the database
- Password hash matches the stored hash
- Associated role is enabled (
Habilitado = true)
User Constraints
- Username uniqueness: The username field has a UNIQUE constraint enforced at the database level
- Code uniqueness: The code field has a unique index to prevent duplicates
- Role requirement: All users must have a valid role assigned (foreign key constraint)
Model Reference
The C# model for User (TechCore.Models.User) includes:
Best Practices
Password Security
Password Security
- Always hash passwords using industry-standard algorithms
- Never log or display password values
- Implement password strength requirements
- Consider implementing password expiration policies
User Code Management
User Code Management
- Establish a consistent code format (e.g., USR001, USR002)
- Keep codes short but meaningful
- Use codes for display purposes, not for authentication
Email and Phone Validation
Email and Phone Validation
- Validate email format before storing
- Implement phone number formatting standards
- Consider making email required for password recovery
Audit Trail
Audit Trail
- The
CreatedDatefield automatically tracks when accounts are created - Consider adding additional audit fields (modified date, modified by)
- Track user actions through related entities (Compras, Venta)