add validate email and generate uuid
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace hack::container
|
||||
{
|
||||
|
||||
21
src/security/generate_uuid.hpp
Normal file
21
src/security/generate_uuid.hpp
Normal 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;
|
||||
}
|
||||
}
|
||||
13
src/security/validate_email.hpp
Normal file
13
src/security/validate_email.hpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user