A simple user authentication service written in Go, using SQLite for data storage. The service supports user registration, login, account deletion, and password change functionalities.
- User Registration: Allows new users to register with a username and password.
- User Login: Authenticates users with their username and password.
- Delete Account: Allows users to delete their account by providing their username and password.
- Change Password: Allows users to change their password after providing their current password.
- Golang
- SQLite
- bcrypt
- Gorilla Mux
-
Clone the Repository
git clone https://github.com/kaynhvh/registerlogin.git cd registerlogin -
Install Dependencies
Ensure you have Go installed on your system. Install the necessary Go packages:
go mod tidy
-
Initialize the Database
The application initializes the SQLite database automatically upon startup. Ensure the directory where the database file will be created has appropriate write permissions.
-
Run the Application
Start the server with the following command:
make run
The server will be accessible at
http://localhost:8080.
-
URL:
/register -
Method:
POST -
Request Body:
{ "username": "string", "password": "string" } -
Success Response:
-
Code:
201 Created -
Content:
{ "message": "User registered successfully" }
-
-
Error Response:
- Code:
400 Bad Requestor409 Conflict(for username already taken)
- Code:
-
URL:
/login -
Method:
POST -
Request Body:
{ "username": "string", "password": "string" } -
Success Response:
-
Code:
200 OK -
Content:
{ "message": "Login successful" }
-
-
Error Response:
- Code:
401 Unauthorized(for invalid credentials)
- Code:
-
URL:
/delete -
Method:
DELETE -
Request Body:
{ "username": "string", "password": "string" } -
Success Response:
-
Code:
204 No Content -
Content:
{ "message": "Successfully deleted", "username": "string" }
-
-
Error Response:
- Code:
400 Bad Requestor401 Unauthorized(for invalid password) or404 Not Found(for user not found)
- Code:
-
URL:
/change-password -
Method:
PUT -
Request Body:
{ "username": "string", "old_password": "string", "new_password": "string" } -
Success Response:
-
Code:
200 OK -
Content:
{ "message": "Password changed successfully" }
-
-
Error Response:
- Code:
400 Bad Requestor401 Unauthorized(for invalid old password)
- Code: