This project is an Identity and Access Management (IAM) system protected against DDoS attacks using the Proof of Work mechanism. Clients must solve a cryptographic puzzle before logging into the server.
- Proof of Work Protection: SHA-256 based difficulty adjustment
- JWT Validation: Secure token management
- Browser-Based Interface: Easy testing with web UI
- Dynamic Difficulty Levels: Adjustable difficulty per request
- Challenge Validity: Timeout control (5 minutes)
- Framework: Spring Boot 4.0.0
- Java: JDK 21
- Token: JJWT 0.11.5
- Build Tool: Maven
src/
├── main/
│ ├── java/org/ybarlas/pow/
│ │ ├── PowApplication.java # Spring Boot main class
│ │ ├── controller/
│ │ │ └── IamController.java # API endpoints
│ │ ├── model/
│ │ │ ├── Challenge.java # Challenge record
│ │ │ ├── ChallengeResponse.java # Challenge response
│ │ │ ├── LoginRequest.java # Login request
│ │ │ └── LoginResponse.java # Login response
│ │ ├── service/
│ │ │ └── ProofOfWorkService.java # PoW logic
│ │ └── util/
│ │ └── JWTUtils.java # JWT operations
│ └── resources/
│ ├── application.properties # Configuration
│ └── static/
│ └── index.html # Web UI
└── test/
└── java/org/ybarlas/pow/
├── controller/
│ └── IamControllerIntegrationTest.java
└── service/
└── ProofOfWorkServiceTest.java
-
Challenge Generation (
/api/iam/challenge)- Server creates a JWT containing random data and difficulty level
- Default difficulty: 4 (hash starting with 4 zeros)
- Validity period: 5 minutes
-
PoW Solving (Client side)
- Client computes SHA-256 hash of
data + nonce - Increments nonce until difficulty level is reached
- Stops when hash with first
ncharacters as zeros is found
- Client computes SHA-256 hash of
-
PoW Verification (
/api/iam/login)- Server validates the JWT
- Recalculates hash with nonce and verifies difficulty level
- Proceeds to user authentication if successful
| Difficulty | Average Nonce | Computation |
|---|---|---|
| 1 | ~16 | Very easy |
| 2 | ~256 | Easy |
| 3 | ~4,096 | Medium |
| 4 | ~65,536 | Hard |
| 5 | ~1,048,576 | Very hard |
- Java 21+
- Maven 3.6+
# Clone the repository
git clone https://github.com/yunusbarlas/pow-example.git
cd pow
# Compile with Maven
mvn clean install
# Start the application
mvn spring-boot:runThe application will run at http://localhost:8090.
GET /api/iam/challenge
Response:
{
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"challenge": "randomBase64String",
"difficulty": 4
}POST /api/iam/login
Content-Type: application/json
{
"username": "demo",
"password": "password123",
"challenge": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"nonce": 1234567
}
Response (Successful):
{
"success": true,
"message": "Login successful",
"token": "token_12345678-1234-1234-1234-123456789012"
}
Response (Failed):
{
"success": false,
"message": "Invalid proof of work",
"token": null
}Default demo account:
- Username:
demo - Password:
password123
Visit http://localhost:8090 to perform the following operations:
- Get challenge from server
- Solve PoW on client side
- Login with the solution
- Receive token on successful authentication
mvn testThis README.md file, style in the index.html, and the following test classes were generated using AI:
IamControllerIntegrationTest.javaProofOfWorkServiceTest.java
The rest of the codebase and core logic were manually implemented.
Yunus Barlas
Last Updated: November 2025