This project is a simple Spring Boot application demonstrating 2FA authentication using TOTP (Time-based One-Time Password), compatible with Google Authenticator, Authy, and similar apps.
- User registration and login
- Enable/disable TOTP 2FA per user
- TOTP QR code generation for easy setup in authenticator apps
- PostgreSQL database integration
- Java 17+
- Maven
- Docker & Docker Compose
git clone [email protected]:Aprendendo-programacao/totp-authentication.git
cd totp-authentication
docker-compose up -d
This will start a PostgreSQL 17.4 instance with the following credentials:
- Database:
totp_auth_db - User:
totp_user - Password:
totp_pass_123
./mvnw spring-boot:run
The application will start on http://localhost:8080.
- Register a new user at
/register. - Login at
/login. - After login, you will be prompted to enable TOTP 2FA:
- Scan the QR code with your authenticator app (Google Authenticator, Authy, etc).
- Enter the 6-digit code from your app to activate 2FA.
- On subsequent logins, you will be required to enter the TOTP code.
- Passwords are stored in plain text for demo purposes. Do not use in production!
- TOTP validation is implemented according to RFC 6238.
- The UI is intentionally minimal for demonstration and testing.
To stop the PostgreSQL container:
docker-compose down