From 489701dfc49fabe8ef176be4a4a30ecaa5099ee5 Mon Sep 17 00:00:00 2001 From: Ian Duncan <76043277+dr8co@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:24:36 +0300 Subject: [PATCH 1/4] Improve password reused detection and printing This change streamlines the process of detecting reused passwords. A map has been introduced to store the count of sites where the passwords are being reused. Reused passwords are now printed in descending order of counts, providing more valuable information to users about which password has the most reuse. It also adds comments to clarify the purpose of the changes in the code. This makes the code more maintainable and accessible to other developers. --- src/passwordManager/passwordManager.cpp | 45 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/passwordManager/passwordManager.cpp b/src/passwordManager/passwordManager.cpp index f7fda75..37f468d 100644 --- a/src/passwordManager/passwordManager.cpp +++ b/src/passwordManager/passwordManager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace fs = std::filesystem; using string = std::string; @@ -69,6 +70,17 @@ inline constexpr void printPasswordDetails(const auto &pw, const bool &isStrong } +/// \brief This function computes the strength of each password in the provided list of passwords. +/// +/// The function iterates over the list of passwords and for each password, it checks if the password is strong or not. +/// The result of this check (a boolean value) is stored in the corresponding index in the pwStrengths vector. +/// A password is considered strong if it meets certain criteria defined in the isPasswordStrong function. +/// +/// \param passwords A vector of tuples, where each tuple represents a password record. +/// \param pwStrengths A vector of boolean values where each element represents the strength of the corresponding password +/// in the passwords vector. It is resized to match the size of the passwords vector. +/// +/// \note This function is always inlined by the compiler. inline constexpr void computeStrengths #if __clang__ [[clang::always_inline]] @@ -504,6 +516,7 @@ inline void importPasswords(privacy::vector &passwords, std::ve privacy::vector duplicates; duplicates.reserve(imports.size()); + // Find the passwords that already exist in the database std::ranges::set_intersection(imports, passwords, std::back_inserter(duplicates), [](const auto &pw1, const auto &pw2) { return comparator(pw1, pw2); @@ -631,21 +644,31 @@ inline void analyzePasswords(privacy::vector &passwords, std::v true); } else printColor("No weak passwords found. Keep it up!\n", 'g', true); - // Print sites with reused passwords - std::size_t reused{0}; + // Find reused passwords + using PasswordSites = std::pair>; + std::multimap> countMap; + for (const auto &entry: passwordMap) { - const std::unordered_set &sites = entry.second; + const auto &sites = entry.second; if (const auto &x = sites.size(); x > 1) { - printColor("Password '", 'y'); - printColor(entry.first, 'r'); - printColor(std::format("' is reused on {} sites:", x), 'y', true); - for (const auto &site: sites) - printColor(site + "\n", 'm'); - - std::cout << std::endl; - ++reused; + countMap.insert(std::make_pair(x, PasswordSites(entry.first, sites))); } } + + // Print reused passwords in descending order of counts + std::size_t reused{0}; + for (const auto &[count, password_sites]: countMap) { + printColor("Password '", 'y'); + printColor(password_sites.first, 'r'); + printColor(std::format("' is reused on {} sites:", count), 'y', true); + for (const auto &site: password_sites.second) + printColor(site + "\n", 'm'); + + std::cout << std::endl; + ++reused; + } + + // Print summary if (reused) { printColor(std::format("{} password{} been reused.", reused, reused == 1 ? " has" : "s have"), 'r', true); From 881a32f12283a96f97b4e3c8278a4be9a9e5e60d Mon Sep 17 00:00:00 2001 From: Ian Duncan <76043277+dr8co@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:46:46 +0300 Subject: [PATCH 2/4] Refactor BLAKE3 build step in GitHub Workflow The workflow file 'cmake-multi-platform.yml' for multi-platform CMake builds has been modified to simplify and improve the BLAKE3 installation process. Instead of directly cloning and building BLAKE3 inside the job, an install script was incorporated which is called based on the operating system detected. This implementation ensures better OS compatibility and enhances the overall clarity and maintainability of the code. --- .github/workflows/cmake-multi-platform.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index a0b477b..2309018 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -58,15 +58,20 @@ jobs: sudo apt update sudo apt install -y cmake ninja-build gcc-13 g++-13 clang-17 lldb-17 lld-17 libc++-17-dev libc++abi-17-dev \ libomp-17-dev libgcrypt20 openssl libreadline8 libsodium23 libsodium-dev + + + - uses: actions/checkout@v3 # Install BLAKE3 - name: Build BLAKE3 run: | - git clone https://github.com/BLAKE3-team/BLAKE3.git - cd BLAKE3/c - cmake -B build -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -G Ninja - sudo cmake --build build --config Release --target install -j 4 - + OS=${{ matrix.os }} + COMMAND="./scripts/install-blake3.sh ${{ matrix.c_compiler }}" + if [ "$OS" == "macos-13" ]; then + $COMMAND + elif [ "$OS" == "ubuntu-latest" ]; then + sudo $COMMAND + fi - uses: actions/checkout@v3 From 3562d74902da9bea667129bcfb85325372dd4a5c Mon Sep 17 00:00:00 2001 From: Ian Duncan <76043277+dr8co@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:49:12 +0300 Subject: [PATCH 3/4] Update script naming convention for BLAKE3 install The renaming of 'install_blake3.sh' to 'install-blake3.sh' complies with standard Unix-like operating systems naming conventions, enhancing cross-platform compatibility. It increases the readability, uniformity and makes the script name easier to type and remember. --- install_blake3.sh => install-blake3.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename install_blake3.sh => install-blake3.sh (100%) diff --git a/install_blake3.sh b/install-blake3.sh similarity index 100% rename from install_blake3.sh rename to install-blake3.sh From 37c3f7e918abd15cb3e3911d127ec0b248368d72 Mon Sep 17 00:00:00 2001 From: Ian Duncan <76043277+dr8co@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:54:09 +0300 Subject: [PATCH 4/4] Move install and build scripts to scripts directory The scripts 'install-blake3.sh' and 'buildscript.sh' have been moved to the 'scripts' directory. This provides better organization and clarity of the project structure, making the scripts easier to locate and manage. --- buildscript.sh => scripts/buildscript.sh | 0 install-blake3.sh => scripts/install-blake3.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename buildscript.sh => scripts/buildscript.sh (100%) rename install-blake3.sh => scripts/install-blake3.sh (100%) diff --git a/buildscript.sh b/scripts/buildscript.sh similarity index 100% rename from buildscript.sh rename to scripts/buildscript.sh diff --git a/install-blake3.sh b/scripts/install-blake3.sh similarity index 100% rename from install-blake3.sh rename to scripts/install-blake3.sh