Skip to content

Commit

Permalink
Hashed password, adaugat .env file in arhiva, mutat partea de psql in…
Browse files Browse the repository at this point in the history
… script separat
  • Loading branch information
Duta-Sebastian committed Dec 23, 2024
1 parent 61598e5 commit f3729c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 3 additions & 6 deletions .github/actions/configure-PostgreSQL/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ runs:
if: runner.os == 'Linux'
run: |
sudo systemctl start postgresql.service
sudo -u postgres bash ./scripts/configure_postgres.sh
- name: Start MacOS PostgreSQL service
shell: bash
if: runner.os == 'macOS'
run: |
brew install postgresql
brew services start postgresql@14
bash ./scripts/configure_postgres.sh
- name: Start Windows PostgreSQL service
shell: bash
Expand All @@ -26,9 +28,4 @@ runs:
net start $serviceName
export PGPASSWORD="root"
export PATH="$PATH:/c/Program Files/PostgreSQL/14/bin:/c/Program Files/PostgreSQL/14/lib"
- name: Create Database
shell: bash
run: |
psql postgres -c "CREATE USER $DATABASE_USER WITH CREATEDB PASSWORD '${DATABASE_PASSWORD}';"
psql postgres -c "CREATE DATABASE $DATABASE_NAME WITH OWNER $DATABASE_USER;"
bash ./scripts/configure_postgres.sh
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ endif()

include(cmake/CopyHelper.cmake)
copy_files(FILES tastatura.txt COPY_TO_DESTINATION TARGET_NAME ${MAIN_EXECUTABLE_NAME})
copy_files(FILES .env COPY_TO_DESTINATION TARGET_NAME ${MAIN_EXECUTABLE_NAME})
# copy_files(FILES tastatura.txt config.json DIRECTORY images sounds COPY_TO_DESTINATION TARGET_NAME ${MAIN_EXECUTABLE_NAME})
# copy_files(DIRECTORY images sounds COPY_TO_DESTINATION TARGET_NAME ${MAIN_EXECUTABLE_NAME})
8 changes: 5 additions & 3 deletions database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

Database::Database(const bool& withDropTables) {
setConnectionString();
connString = "dbname=oop_db user=oop password=ooppa55 hostaddr=127.0.0.1 port=5432 connect_timeout=10";
connection = std::make_unique<pqxx::connection>(connString);
if (!connection->is_open())
throw std::runtime_error("Database exists but a connection couldn't be established");
Expand All @@ -30,7 +29,7 @@ void Database::createTables(){
CREATE TABLE IF NOT EXISTS USERS (
id SERIAL PRIMARY KEY,
name VARCHAR(20) NOT NULL,
password VARCHAR(20) NOT NULL
password VARCHAR(255) NOT NULL
)
)";

Expand All @@ -50,8 +49,11 @@ void Database::dropTables(){

void Database::addUser(std::string name, std::string password) {
pqxx::work transaction(*connection);
std::string hashQuery = "SELECT crypt($1, gen_salt('bf')) AS hashed_password;";
pqxx::result hashResult = transaction.exec_params(hashQuery,password);
std::string hashedPassword = hashResult[0]["hashed_password"].c_str();
std::string insertUserQuery = "INSERT INTO USERS (name, password) VALUES ($1, $2);";
transaction.exec_params(insertUserQuery, name, password);
transaction.exec_params(insertUserQuery, name, hashedPassword);
transaction.commit();
}

Expand Down
5 changes: 5 additions & 0 deletions scripts/configure_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

psql -h 127.0.0.1 -U postgres -c "CREATE USER $DATABASE_USER WITH CREATEDB PASSWORD '$DATABASE_PASSWORD';"
psql -h 127.0.0.1 -U postgres -c "CREATE DATABASE $DATABASE_NAME WITH OWNER $DATABASE_USER;"
psql -h 127.0.0.1 -U postgres -d $DATABASE_NAME -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;"

0 comments on commit f3729c5

Please sign in to comment.