CppSecurity 1.1.2.0
C++ Security Library
Loading...
Searching...
No Matches
google_authenticator.h
Go to the documentation of this file.
1
9#ifndef CPPSECURITY_GOOGLE_AUTHENTICATOR_H
10#define CPPSECURITY_GOOGLE_AUTHENTICATOR_H
11
12#include "password.h"
13
14#include "time/timestamp.h"
15
16namespace CppSecurity {
17
19
33{
34public:
36
40 GoogleAuthenticator(size_t secret_length = 12, size_t pin_length = 6);
44
47
49 size_t secret_length() const noexcept { return _secret_length; }
51 size_t pin_length() const noexcept { return _pin_length; }
52
54
57 std::string GenerateSalt() const;
58
60
64 std::password GenerateSecret(std::string_view password) const;
66
71 std::password GenerateSecret(std::string_view password, std::string_view salt) const;
72
74
79 std::password GenerateURL(std::string_view identifier, std::string_view secret) const;
80
82
88 std::password GenerateQRCodeLink(std::string_view url, size_t width = 100, size_t height = 100) const;
89
91
96 size_t GenerateToken(std::string_view secret, const CppCommon::Timestamp& timestamp = CppCommon::UtcTimestamp()) const;
97
99
105 bool Validate(size_t token, std::string_view secret, const CppCommon::Timestamp& timestamp = CppCommon::UtcTimestamp()) const;
107
114 bool Validate(size_t token, std::string_view password, std::string_view salt, const CppCommon::Timestamp& timestamp = CppCommon::UtcTimestamp()) const;
115
116private:
117 size_t _secret_length;
118 size_t _pin_length;
119};
120
123} // namespace CppSecurity
124
125#endif // CPPSECURITY_GOOGLE_AUTHENTICATOR_H
size_t pin_length() const noexcept
Get the pin length.
size_t GenerateToken(std::string_view secret, const CppCommon::Timestamp &timestamp=CppCommon::UtcTimestamp()) const
Generate the Google Authenticator token for the given secret and UTC timestamp.
std::password GenerateURL(std::string_view identifier, std::string_view secret) const
Generate the Google Authenticator URL.
std::string GenerateSalt() const
Generate the unique password salt.
GoogleAuthenticator & operator=(GoogleAuthenticator &&)=default
std::password GenerateQRCodeLink(std::string_view url, size_t width=100, size_t height=100) const
Generate the Google Authenticator QR Code link.
GoogleAuthenticator & operator=(const GoogleAuthenticator &)=default
GoogleAuthenticator(const GoogleAuthenticator &)=default
std::password GenerateSecret(std::string_view password) const
Generate the Google Authenticator secret from the given user password.
GoogleAuthenticator(GoogleAuthenticator &&)=default
size_t secret_length() const noexcept
Get the secret length.
bool Validate(size_t token, std::string_view secret, const CppCommon::Timestamp &timestamp=CppCommon::UtcTimestamp()) const
Validate the Google Authenticator token over the given secret and UTC timestamp.
Password string.
Definition password.h:53
Password string definition.