Functions to generate secure cookies

This commit is contained in:
Tina_Azure
2023-04-22 23:15:05 +02:00
parent c97f28200d
commit c21de31cb1

View File

@ -295,4 +295,30 @@ namespace Utilities {
loggedIn = true; loggedIn = true;
return loggedIn; return loggedIn;
} }
/*
* Generates a secure cookie
*/
std::string generateSecureCookie(const std::string& value, bool stayLoggedIn) {
std:: string secureCookieValue = value;
secureCookieValue += "; HttpOnly"; // avoid JS from Accessing cookie
secureCookieValue += "; Secure"; // set cookie to be secure
secureCookieValue += "; Path=/";
if (stayLoggedIn)
secureCookieValue += "; Expires=Fri, 31 Dec 9999 23:59:59 GMT"; //max value since cookies can't be set to never expire else it will simply be a session cookie
return secureCookieValue;
}
/*
* Generates the value to create a secure cookie with the value representing a logged-in session
*/
std::string generateSecureCookieLoginKeyValue(const std::string& loginKeyValue, bool stayLoggedIn) {
return generateSecureCookie(loginKeyValue, stayLoggedIn);
}
/*
* generates the value to create a secure cookie with the value representing a logged-in FreelancerID
*/
std::string generateSecureCookieFreelancerEmailValue(const std::string& freelancerEmailValue, bool stayLoggedIn) {
return generateSecureCookie(freelancerEmailValue, stayLoggedIn);
}
} }