Compare commits
No commits in common. "master" and "circleci-project-setup" have entirely different histories.
master
...
circleci-p
13
.circleci/config.yml
Normal file
13
.circleci/config.yml
Normal file
@ -0,0 +1,13 @@
|
||||
# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference
|
||||
version: 2.1
|
||||
# Use a package of configuration called an orb.
|
||||
orbs:
|
||||
# Declare a dependency on the welcome-orb
|
||||
welcome: circleci/welcome-orb@0.4.1
|
||||
# Orchestrate or schedule a set of jobs
|
||||
workflows:
|
||||
# Name the workflow "welcome"
|
||||
welcome:
|
||||
# Run the welcome/run job in its own container
|
||||
jobs:
|
||||
- welcome/run
|
@ -12,20 +12,11 @@ jobs:
|
||||
# well on Windows or Mac. You can convert this to a matrix build if you need
|
||||
# cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-gitea
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
- name: Prep For Local Builds
|
||||
run: echo "${LOCIP} gitea.comnenos" >> /etc/hosts
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install Build Tools
|
||||
run: |
|
||||
apt update
|
||||
apt -y --no-install-recommends install build-essential clang cmake gdb git wget
|
||||
|
||||
- name: Create Build Environment
|
||||
# Some projects don't allow in-source building, so create a separate build directory
|
||||
# We'll use this as our working directory for all subsequent commands
|
@ -1,18 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(passwdgen VERSION 1.0)
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
project(passwdgen)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Create a library with the core functionality
|
||||
add_library(passwdgen_lib passwdgen.cpp)
|
||||
|
||||
# Main application
|
||||
add_executable(passwdgen main.cpp)
|
||||
target_link_libraries(passwdgen passwdgen_lib)
|
||||
|
||||
# Enable testing
|
||||
enable_testing()
|
||||
|
||||
# Add test directory
|
||||
add_subdirectory(tests)
|
||||
add_executable(passwdgen main.cpp)
|
38
README.md
38
README.md
@ -1,38 +0,0 @@
|
||||
# passwdgen
|
||||
### a rudimentary random string password generator
|
||||
|
||||
For demo purposes only
|
||||
|
||||
## Build
|
||||
|
||||
**Bare Bones**
|
||||
```bash
|
||||
mkdir build
|
||||
g++ -o build/passwdgen ./passwdgen.cpp
|
||||
```
|
||||
|
||||
**From CMAKE**
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
Then, just copy the compiled binary to somewhere on your $PATH
|
||||
|
||||
## Testing
|
||||
|
||||
To run the tests:
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
ctest
|
||||
```
|
||||
|
||||
or directly:
|
||||
```bash
|
||||
./tests/passwdgen_test
|
||||
```
|
BIN
bin/linux/passwdgen
Executable file
BIN
bin/linux/passwdgen
Executable file
Binary file not shown.
BIN
bin/osx/passwdgen
Executable file
BIN
bin/osx/passwdgen
Executable file
Binary file not shown.
88
main.cpp
88
main.cpp
@ -1,46 +1,68 @@
|
||||
//
|
||||
// Created by gmgauthier on 05/09/25.
|
||||
//
|
||||
// main.cpp
|
||||
#include "passwdgen.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <random>
|
||||
|
||||
std::string random_string(std::size_t length, bool punc) {
|
||||
std::string CHARACTERS;
|
||||
std::string ALPHANUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
std::string SPECIALS = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
|
||||
if (punc) {
|
||||
CHARACTERS = ALPHANUM.append(SPECIALS);
|
||||
} else {
|
||||
CHARACTERS = ALPHANUM;
|
||||
}
|
||||
std::random_device random_device;
|
||||
std::mt19937 generator(random_device());
|
||||
std::uniform_int_distribution<> distribution(0, CHARACTERS.size() - 1);
|
||||
|
||||
std::string random_string;
|
||||
for (std::size_t i = 0; i < length; ++i) {
|
||||
random_string += CHARACTERS[distribution(generator)];
|
||||
}
|
||||
return random_string;
|
||||
}
|
||||
|
||||
void show_usage(std::string binname) {
|
||||
std::cerr << "Usage: " << binname << " [OPTIONS] " << std::endl
|
||||
<< "Options:" << std::endl
|
||||
<< "\t-h, --help \t\tShow this help message" << std::endl
|
||||
<< "\t-l, --length \t\tThe length of the password (default: 32)" << std::endl
|
||||
<< "\t-p, --punctuation \t\tToggle special characters (default: false)"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int passwordLength = 0;
|
||||
std::string passlenstr;
|
||||
int passlen;
|
||||
bool punc = false;
|
||||
|
||||
if (argc < 1) {
|
||||
std::cout << random_string(32, false) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string arg = argv[i];
|
||||
if ((arg == "-h") || (arg == "--help")) {
|
||||
show_usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (arg == "-p") {
|
||||
punc = true;
|
||||
} else if ((arg == "-l") || (arg == "--length")) {
|
||||
if (not argv[i +1]) {
|
||||
std::cerr << "Specify a password length" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::string passwordLengthStr = argv[i + 1];
|
||||
try {
|
||||
passwordLength = std::stoi(passwordLengthStr);
|
||||
} catch ([[maybe_unused]] const std::invalid_argument& e){
|
||||
std::cerr << "Length must be a valid integer" << std::endl;
|
||||
return 1;
|
||||
} else {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string arg = argv[i];
|
||||
if ((arg == "-h") || (arg == "--help")) {
|
||||
show_usage(argv[0]);
|
||||
return 0;
|
||||
} else if (arg == "-p") {
|
||||
punc = true;
|
||||
} else if ((arg == "-l") || (arg == "--length")) {
|
||||
passlenstr = argv[i + 1];
|
||||
if (passlenstr.empty()) {
|
||||
std::cerr << "--destination option requires one argument." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (passwordLength == 0) {
|
||||
passwordLength = 32;
|
||||
if (passlenstr.empty()) {
|
||||
passlenstr = "32";
|
||||
}
|
||||
passlen = std::stoi(passlenstr);
|
||||
std::string password = random_string(passlen, punc);
|
||||
std::cout << password << std::endl;
|
||||
return 0;
|
||||
}
|
||||
std::string password = random_string(passwordLength, punc);
|
||||
std::cout << password << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
// passwdgen.cpp
|
||||
#include "passwdgen.h"
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
std::string random_string(std::size_t length, bool punc) {
|
||||
std::string CHARACTERS;
|
||||
std::string ALPHANUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const std::string SPECIALS = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
|
||||
if (punc) {
|
||||
CHARACTERS = ALPHANUM.append(SPECIALS);
|
||||
} else {
|
||||
CHARACTERS = ALPHANUM;
|
||||
}
|
||||
|
||||
std::random_device random_device;
|
||||
std::mt19937 generator(random_device());
|
||||
std::uniform_int_distribution<> distribution(0, static_cast<int>(CHARACTERS.size() - 1));
|
||||
|
||||
std::string random_string;
|
||||
for (std::size_t i = 0; i < length; ++i) {
|
||||
random_string += CHARACTERS[distribution(generator)];
|
||||
}
|
||||
return random_string;
|
||||
}
|
||||
|
||||
void show_usage(const std::string& name) {
|
||||
std::cerr << "Usage: " << name << " [OPTIONS] " << std::endl
|
||||
<< "Options:" << std::endl
|
||||
<< "\t-h, --help \t\tShow this help message" << std::endl
|
||||
<< "\t-l, --length [n] \t\tThe length of the password (default: 32)" << std::endl
|
||||
<< "\t-p, --punctuation \t\tToggle special characters (default: false)"
|
||||
<< std::endl;
|
||||
}
|
10
passwdgen.h
10
passwdgen.h
@ -1,10 +0,0 @@
|
||||
// passwdgen.h
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Core password generation functionality
|
||||
std::string random_string(std::size_t length, bool punc);
|
||||
|
||||
// Help message display
|
||||
void show_usage(const std::string& name);
|
@ -1,17 +0,0 @@
|
||||
# tests/CMakeLists.txt
|
||||
add_executable(passwdgen_test passwdgen_test.cpp)
|
||||
|
||||
# Link against the library that contains the functions we want to test
|
||||
target_link_libraries(passwdgen_test passwdgen_lib)
|
||||
|
||||
# Register the test with CTest
|
||||
add_test(
|
||||
NAME passwdgen_tests
|
||||
COMMAND passwdgen_test
|
||||
)
|
||||
|
||||
# Define what it means for the test to pass
|
||||
set_tests_properties(passwdgen_tests
|
||||
PROPERTIES PASS_REGULAR_EXPRESSION "All tests passed!"
|
||||
)
|
||||
|
@ -1,48 +0,0 @@
|
||||
// tests/passwdgen_test.cpp
|
||||
#include "../passwdgen.h"
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <cassert>
|
||||
|
||||
void test_random_string_length() {
|
||||
for (const int lengths[] = {0, 1, 10, 32, 100}; const auto length : lengths) {
|
||||
std::string result = random_string(length, false);
|
||||
assert(result.length() == length);
|
||||
|
||||
std::string result_with_punc = random_string(length, true);
|
||||
assert(result_with_punc.length() == length);
|
||||
}
|
||||
std::cout << "Length test passed\n";
|
||||
}
|
||||
|
||||
void test_alphanumeric_only() {
|
||||
const std::regex alphanumeric_only("^[a-zA-Z0-9]*$");
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
std::string result = random_string(20, false);
|
||||
assert(std::regex_match(result, alphanumeric_only));
|
||||
}
|
||||
std::cout << "Alphanumeric test passed\n";
|
||||
}
|
||||
|
||||
void test_with_punctuation() {
|
||||
bool found_special = false;
|
||||
|
||||
for (int i = 0; i < 100 && !found_special; i++) {
|
||||
std::string result = random_string(100, true);
|
||||
if (!std::regex_match(result, std::regex("^[a-zA-Z0-9]*$"))) {
|
||||
found_special = true;
|
||||
}
|
||||
}
|
||||
|
||||
assert(found_special);
|
||||
std::cout << "Punctuation test passed\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_random_string_length();
|
||||
test_alphanumeric_only();
|
||||
test_with_punctuation();
|
||||
std::cout << "All tests passed!\n";
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user