From bb49c6f96b50a02c368663fbf8b905ce9c2d8db3 Mon Sep 17 00:00:00 2001 From: chatlanin Date: Wed, 15 Jun 2022 09:36:23 +0300 Subject: [PATCH] add validate email and generate uuid --- bin/main.cpp | 13 +++++++++++++ meson.build | 22 ++++++++++------------ src/container/container.hpp | 1 + src/security/generate_uuid.hpp | 21 +++++++++++++++++++++ src/security/validate_email.hpp | 13 +++++++++++++ 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 src/security/generate_uuid.hpp create mode 100644 src/security/validate_email.hpp diff --git a/bin/main.cpp b/bin/main.cpp index b9aaa05..c3d2dbb 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -15,6 +15,8 @@ #include "math/matrix.hpp" #include "math/vector.hpp" #include "utils/utils.hpp" +#include "security/validate_email.hpp" +#include "security/generate_uuid.hpp" // for example int f(int a) @@ -187,4 +189,15 @@ int main(int argc, char *argv[]) auto t = hack::utils::exec("pwd"); hack::log::type_trace(t); } + + { + // ec: security::validate_email + std::string email = "asdf@asdf.com"; + hack::log()(hack::security::validate_email(email)); + } + + { + // ec: security::generate_uuid + hack::log()(hack::security::generate_uuid()); + } } diff --git a/meson.build b/meson.build index a268d67..58175cc 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,3 @@ -# https://pixorblog.wordpress.com/2019/07/27/a-meson-starter-script-for-c-projects project( 'hack', 'cpp', @@ -10,25 +9,24 @@ add_project_arguments ( '-Wpedantic', '-Wshadow', '-Wno-comment', - #'-Wno-gnu-zero-variadic-macro-arguments', + '-Wno-gnu-zero-variadic-macro-arguments', '-Wunused-but-set-variable', language: 'cpp' ) -compiler = meson.get_compiler('cpp') -if compiler.get_id() == 'gcc' - message('Compiler: GCC') -elif compiler.get_id() == 'clang' - message('Compiler: LLVM/clang') -endif +############################################################# -boost_dep = dependency('boost') - -args = [] deps = [] -deps += boost_dep +args = [] inc = [] +deps += dependency('boost') +deps += dependency('uuid') + +args += '-luuid' + +############################################################# + subdir('src') subdir('bin') subdir('tests') diff --git a/src/container/container.hpp b/src/container/container.hpp index 4f03b51..e5eaa29 100644 --- a/src/container/container.hpp +++ b/src/container/container.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace hack::container { diff --git a/src/security/generate_uuid.hpp b/src/security/generate_uuid.hpp new file mode 100644 index 0000000..1204d0a --- /dev/null +++ b/src/security/generate_uuid.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +namespace hack::security +{ + inline std::string generate_uuid() + { + std::string uuid; + uuid_t uuid_obj; + uuid_generate_time_safe(uuid_obj); + char uuid_ch[37]; + uuid_unparse_lower(uuid_obj, uuid_ch); + std::stringstream ss; + ss << uuid_ch; + ss >> uuid; + return uuid; + } +} diff --git a/src/security/validate_email.hpp b/src/security/validate_email.hpp new file mode 100644 index 0000000..44a8e0d --- /dev/null +++ b/src/security/validate_email.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace hack::security +{ + inline bool validate_email(std::string& email) + { + const std::regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"); + return std::regex_match(email, pattern); + } +}