add security section
This commit is contained in:
parent
096ef69938
commit
159dfed234
14
src/hack/security/is_link.hpp
Executable file
14
src/hack/security/is_link.hpp
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace hack::security
|
||||||
|
{
|
||||||
|
inline bool is_link(const std::string& s)
|
||||||
|
{
|
||||||
|
static const std::regex e("^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$", std::regex_constants::icase);
|
||||||
|
return std::regex_match (s, e);
|
||||||
|
}
|
||||||
|
}
|
15
src/hack/security/is_string.hpp
Executable file
15
src/hack/security/is_string.hpp
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace hack::security
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct is_string : public std::disjunction<std::is_same<char*,
|
||||||
|
typename std::decay_t<T>>,
|
||||||
|
std::is_same<const char*,
|
||||||
|
typename std::decay_t<T>>,
|
||||||
|
std::is_same<std::string,
|
||||||
|
typename std::decay_t<T>>> {};
|
||||||
|
}
|
27
src/hack/security/uuid.hpp
Executable file
27
src/hack/security/uuid.hpp
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
#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[UUID_STR_LEN];
|
||||||
|
uuid_unparse_lower(uuid_obj, uuid_ch);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << uuid_ch;
|
||||||
|
ss >> uuid;
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool validate_uuid(const std::string& s)
|
||||||
|
{
|
||||||
|
static const std::regex e("^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$", std::regex_constants::icase);
|
||||||
|
return std::regex_match(s, e);
|
||||||
|
}
|
||||||
|
}
|
13
src/hack/security/validate_email.hpp
Executable file
13
src/hack/security/validate_email.hpp
Executable 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user