This is a client-server application that provides an arithmetic service with user authentication. The server is built using Pyro4, and the client can connect to the server, register or log in, and then perform arithmetic operations like addition, subtraction, multiplication, division, and factorial calculation.
- Python 3.11
- Pyro4 library
- pymongo library
- bcrypt library
- MongoDB Atlas account (or a local MongoDB instance)
-
Clone the repository or copy the
server.py
andclient.py
files to your local machine. -
Create a virtual environment. You can do this by using the following command in your terminal:
python3 -m venv env
- Activate the virtual environment. On Windows, use:
.\env\Scripts\activate
On Unix or MacOS use:
source env/bin/activate
- Install the required packages using pip:
pip install -r requirements.txt
- Update the MongoDB connection URI in the
server.py
file with your MongoDB Atlas connection string or local MongoDB instance URI.
uri = "mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority&appName=auth-cluster"
- Open a terminal and navigate to the directory containing the server.py file.
- Run the following command to start the server:
python server.py
- The server will print the Pyro URI for clients to connect, e.g., Ready. Object URI = PYRO:obj_b1a3b9a3a7a64e6ba5b9c7a6a5a6a5a6@localhost:51892
- Open another terminal and navigate to the directory containing the client.py file.
- Run the following command and enter the Pyro URI printed by the server when prompted:
python client.py
- You will be asked if you want to register a new user or log in. Enter r for registration or l for login.
- If registering, provide a username and password when prompted.
- If logging in, provide your registered username and password.
- Upon successful authentication, you can perform arithmetic operations like addition, subtraction, multiplication, division, and factorial calculation.
- The server logs information to a server.log file in the same directory.
- The client logs information to the console.
- User credentials are stored in a MongoDB database, and passwords are hashed using bcrypt for security.
- Only authenticated users can perform arithmetic operations.
- The server handles errors and exceptions gracefully.