A robust session-based authentication system built with Go, featuring Redis for session management and PostgreSQL for persistent data storage.
- Secure user authentication with session management
- Dual database system: PostgreSQL (persistent data) + Redis (session storage)
- Session tracking with device info and location
- Protection against brute force attacks
- Active session management and monitoring
- Automatic session expiration
- Secure password handling with bcrypt
-
Session Management
- Session tokens stored in Redis with TTL
- Device and location tracking for each session
- Active session monitoring
-
Brute Force Protection
- Maximum login attempt limits
- Cool-down period after failed attempts
- Automatic account protection
-
Secure Authentication
- Bcrypt password hashing
- HTTP-only cookies for session tokens
- Transaction-based operations for data consistency
- Go 1.x
- PostgreSQL
- Redis
- GNU Make (for using Makefile commands)
- Clone the repository:
git clone https://github.com/Krish-Depani/auth-session-manager.git
cd auth-session-manager
- Install dependencies:
go mod download
-
Rename the
.env.example
file to.env
and update the following environment variables as needed -
Set up the databases:
- Create PostgreSQL database
- Start Redis server
- Run migrations:
make migrate-up
make start-dev
make start-prod
POST /auth/register
- Register a new userPOST /auth/login
- User loginPOST /auth/logout
- User logout (requires authentication)
GET /auth/user/me
- Get current user details (requires authentication)GET /auth/user/sessions
- Get active sessions (requires authentication)
make migrate-create name=migration_name
- Up:
make migrate-up
- Down:
make migrate-down n=1
- Status:
make migrate-status
- Force Version:
make migrate-force version=1
├── bin/ # Compiled binary
├── config/ # Configuration files
├── controllers/ # Request handlers
├── database/ # Database connections and migrations
├── models/ # Data models
├── routes/ # API route definitions
├── utils/ # Utility functions
└── validators/ # Request validation