Skip to content
Snippets Groups Projects
Commit 72562e8c authored by Chude, Chiamaka A (PG/T - Comp Sci & Elec Eng)'s avatar Chude, Chiamaka A (PG/T - Comp Sci & Elec Eng)
Browse files

"Final commit for User Microservice. Added docker and docker compose files...

 "Final commit for User Microservice. Added docker and docker compose files for containerisation. Bug were also removed after testing."
parent cfee6930
Branches Chiamaka_Chude
No related tags found
No related merge requests found
Showing
with 0 additions and 303 deletions
FROM python:3.11.4
#Copy requirements
COPY requirements.txt /user_ms/
COPY app /user_ms/
#Set working direcroty
WORKDIR /user_ms
#Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
#Install other libraries in container
RUN apt-get update && apt-get install -y \
unixodbc \
unixodbc-dev \
iputils-ping\
apt-transport-https \
gcc\
curl \
gnupg \
freetds-dev \
tdsodbc \
&& rm -rf /var/lib/apt/lists/*
#Install ODBC Driver for Microsoft SQL Server Section...
#Source: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16&tabs=debian18-install%2Calpine17-install%2Cdebian8-install%2Credhat7-13-install%2Crhel7-offline
#Add Microsoft repository GPG key
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
#Add the Microsoft SQL Server repository for Debian 12
RUN curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
#Add Microsoft GPG key
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg
#Add the Microsoft SQL Server repository for Debian 12
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list
#Update package list
RUN apt-get update
#Install ODBC Driver 17 for SQL Server
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
#Install mssql-tools
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN bash -c "echo 'export PATH=\"$PATH:/opt/mssql-tools/bin\"' >> ~/.bashrc && source ~/.bashrc"
#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc && source ~/.bashrc
#Install unixodbc-dev and kerberos library
RUN apt-get install -y libgssapi-krb5-2
#Set environment variables for ODBC configuration
ENV ODBCINI=/etc/odbc.ini
ENV ODBCSYSINI=/etc
CMD ["python", "index.py"]
\ No newline at end of file
FROM mcr.microsoft.com/mssql/server:2022-latest
# Set environment variables
ENV SA_PASSWORD WebTechGroup3
ENV ACCEPT_EULA=Y
COPY User_Management.bak /var/opt/mssql/data/
# Change user permissions
USER root
RUN chown -R mssql:mssql /var/opt/mssql/data
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# Expose the default SQL Server port
EXPOSE 1433
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Define the default command to run when the container starts
CMD ["/opt/mssql/bin/sqlservr"]
\ No newline at end of file
FROM python:3.11.4
#Copy requirements
COPY requirements.txt /user_ms/
COPY app /user_ms/
#Set working direcroty
WORKDIR /user_ms
#Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
#Install other libraries in container
RUN apt-get update && apt-get install -y \
unixodbc \
unixodbc-dev \
iputils-ping\
apt-transport-https \
gcc\
curl \
gnupg \
freetds-dev \
tdsodbc \
&& rm -rf /var/lib/apt/lists/*
#Add Microsoft repository GPG key
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
#Add the Microsoft SQL Server repository for Debian 12
RUN curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
#Add Microsoft GPG key
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg
#Add the Microsoft SQL Server repository for Debian 12
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list
#Update package list
RUN apt-get update
#Install ODBC Driver 17 for SQL Server
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
#Optional: Install mssql-tools and add to PATH
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN bash -c "echo 'export PATH=\"$PATH:/opt/mssql-tools/bin\"' >> ~/.bashrc && source ~/.bashrc"
#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc && source ~/.bashrc
#Optional: Install unixodbc-dev and kerberos library
RUN apt-get install -y libgssapi-krb5-2
#Set environment variables for ODBC configuration if needed
ENV ODBCINI=/etc/odbc.ini
ENV ODBCSYSINI=/etc
CMD ["python", "index.py"]
\ No newline at end of file
File deleted
runtime: python312
entrypoint: gunicorn -b :$PORT index:app
\ No newline at end of file
from flask import Flask
from app.models import login
app = Flask(__name__)
from app import routes
if __name__ == '__main__':
app.run(debug=True)
\ No newline at end of file
File deleted
import os
DEBUG = True
SECRET_KEY = "Group3"
PORT = 5000
KAFKA_SERVER = "kafka:9092"
HOST = "0.0.0.0"
\ No newline at end of file
from flask import Flask
from flask import Blueprint
File deleted
File deleted
File deleted
File deleted
File deleted
#This page allows users to change their password
#
#
from flask import Blueprint, jsonify, request, session
from models.changePassword import check_old_password, set_new_password
import hashlib
import secrets
import hmac
change_password_bp = Blueprint("change_password",__name__)
@change_password_bp.route("/user/change_password", methods=["POST"])
def change_password():
user_id = session.get("user_id") #Get user ID from session
if user_id:#checks if user is logges in
if request.method == 'POST':
#User data from front end
data = request.get_json()
email = data.get("email")
old_password = data.get("old_password")
new_password = data.get("new_password")
new_encoded_password = generate_password_hash(new_password)
new_password_hash = new_encoded_password["hash"]
new_password_salt = new_encoded_password["salt"]
new_password_iterations = new_encoded_password["iterations"]
#collect old password, user id and email into json
old_auth = {
"user_id" : user_id,
"email" : email,
"password": old_password
}
#user_old_auth = check_old_password(old_auth)
#send old password to database
old_auth_info, value = check_old_password(old_auth) #function returns certain columns collected from database
if value == 1: #if user exists in database
old_password_hash = old_auth_info.get("PasswordHash")
old_password_salt = old_auth_info.get("PasswordSalt")
old_password_iterations = old_auth_info.get("Iterations")
#password authentication. Calls password fucntions
old_password_info = generate_password_hash(old_password)
is_correct = verify_password(old_password_info, old_password, old_password_salt, old_password_iterations, old_password_hash)
if is_correct == True:#if password is correct
#passes new password information to json
new_auth = {
"user_id" : user_id,
"email" : email,
"password": new_password,
"hash": new_password_hash,
"salt": new_password_salt,
"iterations": new_password_iterations
}
#sends new password to database
new_auth_info = set_new_password(new_auth)
response_data = {"message":"Password is correct"}
return jsonify(new_auth_info, user_id)
else:
response_data = {"error":"Old password is incorrect", "email": email}
return jsonify(response_data)
else:
return {"error" : "Email does not exist"}
return {"error" : "null"}
else:
return {"error" : "User not logged in"}
#password encoding
def generate_password_hash(password):
# Generate a 16-byte salt
salt = secrets.token_bytes(16)
# Define the number of iterations
iterations = 100000
# Generate the hash using PBKDF2-HMAC-SHA-256
hash = hashlib.pbkdf2_hmac('sha256', password.encode(), salt, iterations)
# Return the salt, iterations, and hash, encoded in a way that can be stored in the database
return {
'salt': salt.hex(),
'iterations': iterations,
'hash': hash.hex()
}
#password verification
def verify_password(stored_password_info, submitted_password, salt, iterations, user_hash):
# Convert the stored salt back to bytes
salt = bytes.fromhex(salt)
# Use the same number of iterations as when the password was hashed
iterations = iterations
# Hash the submitted password with the stored salt and iterations
hash = hashlib.pbkdf2_hmac('sha256', submitted_password.encode(), salt, iterations)
# Compare the newly generated hash with the stored hash
# Convert the generated hash to hex for comparison
return hmac.compare_digest(hash.hex(), user_hash)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment