add validate email and generate uuid

This commit is contained in:
chatlanin 2022-06-15 09:36:23 +03:00
parent fa9972b9d5
commit bb49c6f96b
5 changed files with 58 additions and 12 deletions

View File

@ -15,6 +15,8 @@
#include "math/matrix.hpp" #include "math/matrix.hpp"
#include "math/vector.hpp" #include "math/vector.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
#include "security/validate_email.hpp"
#include "security/generate_uuid.hpp"
// for example // for example
int f(int a) int f(int a)
@ -187,4 +189,15 @@ int main(int argc, char *argv[])
auto t = hack::utils::exec("pwd"); auto t = hack::utils::exec("pwd");
hack::log::type_trace(t); 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());
}
} }

View File

@ -1,4 +1,3 @@
# https://pixorblog.wordpress.com/2019/07/27/a-meson-starter-script-for-c-projects
project( project(
'hack', 'hack',
'cpp', 'cpp',
@ -10,25 +9,24 @@ add_project_arguments (
'-Wpedantic', '-Wpedantic',
'-Wshadow', '-Wshadow',
'-Wno-comment', '-Wno-comment',
#'-Wno-gnu-zero-variadic-macro-arguments', '-Wno-gnu-zero-variadic-macro-arguments',
'-Wunused-but-set-variable', '-Wunused-but-set-variable',
language: 'cpp' 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 = []
deps += boost_dep args = []
inc = [] inc = []
deps += dependency('boost')
deps += dependency('uuid')
args += '-luuid'
#############################################################
subdir('src') subdir('src')
subdir('bin') subdir('bin')
subdir('tests') subdir('tests')

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <vector>
namespace hack::container namespace hack::container
{ {

View File

@ -0,0 +1,21 @@
#pragma once
#include <uuid/uuid.h>
#include <regex>
#include <string>
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;
}
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <regex>
#include <string>
namespace hack::security
{
inline bool validate_email(std::string& email)
{
const std::regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return std::regex_match(email, pattern);
}
}