Overview
Ironclad provides a complete authentication system built on industry-standard security practices:- JWT tokens for stateless authentication
- Bcrypt password hashing with configurable cost factors
- Environment-specific security validation
- Clean separation between authentication logic and HTTP layer
Authentication Flow
The authentication flow follows a layered architecture:User Registration
Registration Endpoint
The registration endpoint uses automatic validation viaValidatedJson extractor:
auth_controller.rs:14-20 for the full implementation.
Registration Request DTO
TheRegisterUserRequest uses the validator crate for declarative validation:
auth_dto.rs:6-16 for the complete definition.
Registration Service Logic
TheAuthService::register method implements the complete registration flow:
auth_service.rs:26-61 for the full implementation.
User Login
Login Endpoint
auth_controller.rs:23-29.
Login Request DTO
auth_dto.rs:19-26.
Login Service Logic
The login service verifies credentials and returns a JWT token:auth_service.rs:64-90.
Password Hashing with Bcrypt
Ironclad uses bcrypt for secure password hashing with configurable cost factors.Hashing Passwords
auth.rs:7-12.
Verifying Passwords
auth.rs:15-18.
Bcrypt Configuration
Bcrypt cost factors are validated based on environment:- Production
- Staging
- Development
Minimum cost: 10 (recommended: 12)The application will exit if production cost is below 10:See
validators.rs:33-41.Environment Configuration
Configure bcrypt in your.env file:
Authentication Response
Both registration and login return the same response structure:auth_dto.rs:62-66 and auth_dto.rs:50-59.
Example Response
Security Best Practices
Multi-Layer Validation
Ironclad implements validation at multiple layers:- DTO validation (structure, format) - see Validation
- Strong password rules (complexity requirements)
- Business logic validation (unique email, active account)
- Domain validation (value objects)
Password Requirements
Passwords must meet the following criteria:validator/mod.rs:4-15.
Passwords must contain:
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least one special character
- Minimum 8 characters (enforced by DTO validation)
Account Status Checking
The login flow checks if accounts are active:Example: Complete Registration Flow
Example: Login Flow
Related Documentation
Authorization
Learn about role-based access control and authorization extractors
JWT Tokens
Deep dive into JWT token generation, validation, and claims
Validation
Input validation with the validator crate and custom validators