This project implements authentication services for user management, including functionalities for user registration, login, and password hashing with salt. The services are written in Go and use a secure hashing algorithm to protect user passwords.
Future Development:
- Email services
- Cron job to cleanup data
This project provides a robust authentication system to manage user registration and login processes. It securely stores user passwords using a combination of hashing and salting techniques to ensure security.
! Document
! Video
[https://www.youtube.com/watch?v=ffYCgcDgsfw]
- User Registration
- User Login
- Password Hashing with Salt
- User Authentication
- Error Handling
- Before diving into the setup and usage, it's essential to first understand the flow of the authentication process. This includes how user registration, password hashing, and authentication work together in the system. Database Document: https://docs.google.com/document/d/1UksY_m3XHSLu2WLhkvc7wLOS2bXPRtqLkuNp8OvtzXk/edit?usp=sharing
- Once you understand the flow, I'll provide some images to help illustrate the process and make it easier to follow.
- Go 1.17 or later
- A running instance of a SQL database (e.g., MySQL, PostgreSQL)
- Git
-
Clone the repository:
git clone https://github.com/yourusername/authentication-services.git cd authentication-services
-
Install dependencies:
go mod tidy
-
Database Configuration: Configure your database connection in the config package. Update the config.go file with your database connection details.
-
Environment Variables: Create a .env file in the root directory of the project and set the following variables:
makefile
DB_HOST=your_database_host
DB_PORT=your_database_port
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
- Run the service:
go run main.go
Register a new user: Send a POST request to /register with the following JSON body:
- Registering a new User: Send a POST request to /register with the following JSOn
{
"username": "test",
"password": "Test",
"first_name": "test",
"last_name": "test",
"email": "[email protected]"
}
- Login with an existing user: Send a POST request to /login with the following JSON body:
{
"username": "exampleuser",
"password": "examplepassword"
}
POST /register: Registers a new user. POST /login: Authenticates a user and returns a success message if the credentials are valid.
Example Request
- Register:
curl -X POST http://localhost:8080/register -H "Content-Type: application/json" -d '{"username": "exampleuser", "password": "examplepassword"}'
- Login:
curl -X POST http://localhost:8080/login -H "Content-Type: application/json" -d '{"username": "exampleuser", "password": "examplepassword"}'
migrate create -ext sql -dir Migration/sql -seq create_users_table
make <command_in_makefile>
docker exec -it authentication_redis redis-cli
- CHECK BIT: getbit u:bit 4097051691
- SET BIT : setbit u:bit 4097051691