Google Authenticator.
More...
#include <google_authenticator.h>
|
| GoogleAuthenticator (size_t secret_length=12, size_t pin_length=6) |
| Initialize Google Authenticator with required parameters.
|
|
| GoogleAuthenticator (const GoogleAuthenticator &)=default |
|
| GoogleAuthenticator (GoogleAuthenticator &&)=default |
|
| ~GoogleAuthenticator ()=default |
|
GoogleAuthenticator & | operator= (const GoogleAuthenticator &)=default |
|
GoogleAuthenticator & | operator= (GoogleAuthenticator &&)=default |
|
size_t | secret_length () const noexcept |
| Get the secret length.
|
|
size_t | pin_length () const noexcept |
| Get the pin length.
|
|
std::string | GenerateSalt () const |
| Generate the unique password salt.
|
|
std::password | GenerateSecret (std::string_view password) const |
| Generate the Google Authenticator secret from the given user password.
|
|
std::password | GenerateSecret (std::string_view password, std::string_view salt) const |
| Generate the Google Authenticator secret from the given user password and unique salt.
|
|
std::password | GenerateURL (std::string_view identifier, std::string_view secret) const |
| Generate the Google Authenticator URL.
|
|
std::password | GenerateQRCodeLink (std::string_view url, size_t width=100, size_t height=100) const |
| Generate the Google Authenticator QR Code link.
|
|
size_t | GenerateToken (std::string_view secret, const CppCommon::Timestamp ×tamp=CppCommon::UtcTimestamp()) const |
| Generate the Google Authenticator token for the given secret and UTC timestamp.
|
|
bool | Validate (size_t token, std::string_view secret, const CppCommon::Timestamp ×tamp=CppCommon::UtcTimestamp()) const |
| Validate the Google Authenticator token over the given secret and UTC timestamp.
|
|
bool | Validate (size_t token, std::string_view password, std::string_view salt, const CppCommon::Timestamp ×tamp=CppCommon::UtcTimestamp()) const |
| Validate the Google Authenticator token over the given user password, unique salt and UTC timestamp.
|
|
Google Authenticator.
Google Authenticator allows to generate secrets and validate tokens registered in Google Authenticator software.
Google Authenticator is a software-based authenticator that implements two-step verification services using the Time-based One-time Password Algorithm (TOTP; specified in RFC 6238) and HMAC-based One-time Password algorithm (HOTP; specified in RFC 4226), for authenticating users of mobile applications by Google.
https://en.wikipedia.org/wiki/Google_Authenticator https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2
Thread-safe.
- Examples
- google_authenticator.cpp.
Definition at line 32 of file google_authenticator.h.
◆ GoogleAuthenticator() [1/3]
CppSecurity::GoogleAuthenticator::GoogleAuthenticator |
( |
size_t |
secret_length = 12 , |
|
|
size_t |
pin_length = 6 |
|
) |
| |
Initialize Google Authenticator with required parameters.
- Parameters
-
secret_length | - Secret length (default is 12) |
pin_length | - Pin length (default is 6) |
Definition at line 24 of file google_authenticator.cpp.
◆ GoogleAuthenticator() [2/3]
◆ GoogleAuthenticator() [3/3]
◆ ~GoogleAuthenticator()
CppSecurity::GoogleAuthenticator::~GoogleAuthenticator |
( |
| ) |
|
|
default |
◆ GenerateQRCodeLink()
std::password CppSecurity::GoogleAuthenticator::GenerateQRCodeLink |
( |
std::string_view |
url, |
|
|
size_t |
width = 100 , |
|
|
size_t |
height = 100 |
|
) |
| const |
Generate the Google Authenticator QR Code link.
- Parameters
-
url | - Google Authenticator URL |
width | - QR Code width (default is 100) |
height | - QR Code height (default is 100) |
- Returns
- Generated Google Authenticator QR Code link
- Examples
- google_authenticator.cpp.
Definition at line 67 of file google_authenticator.cpp.
◆ GenerateSalt()
std::string CppSecurity::GoogleAuthenticator::GenerateSalt |
( |
| ) |
const |
◆ GenerateSecret() [1/2]
std::password CppSecurity::GoogleAuthenticator::GenerateSecret |
( |
std::string_view |
password | ) |
const |
◆ GenerateSecret() [2/2]
std::password CppSecurity::GoogleAuthenticator::GenerateSecret |
( |
std::string_view |
password, |
|
|
std::string_view |
salt |
|
) |
| const |
Generate the Google Authenticator secret from the given user password and unique salt.
- Parameters
-
password | - User password |
salt | - Unique password salt |
- Returns
- Generated Google Authenticator secret
Definition at line 47 of file google_authenticator.cpp.
◆ GenerateToken()
size_t CppSecurity::GoogleAuthenticator::GenerateToken |
( |
std::string_view |
secret, |
|
|
const CppCommon::Timestamp & |
timestamp = CppCommon::UtcTimestamp() |
|
) |
| const |
Generate the Google Authenticator token for the given secret and UTC timestamp.
- Parameters
-
secret | - Google Authenticator secret |
timestamp | - UTC timestamp (default is CppCommon::UtcTimestamp()) |
- Returns
- Generated Google Authenticator token
Definition at line 72 of file google_authenticator.cpp.
◆ GenerateURL()
std::password CppSecurity::GoogleAuthenticator::GenerateURL |
( |
std::string_view |
identifier, |
|
|
std::string_view |
secret |
|
) |
| const |
Generate the Google Authenticator URL.
- Parameters
-
identifier | - Google Authenticator identifier |
secret | - Google Authenticator secret |
- Returns
- Generated Google Authenticator URL
- Examples
- google_authenticator.cpp.
Definition at line 62 of file google_authenticator.cpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ pin_length()
size_t CppSecurity::GoogleAuthenticator::pin_length |
( |
| ) |
const |
|
inlinenoexcept |
◆ secret_length()
size_t CppSecurity::GoogleAuthenticator::secret_length |
( |
| ) |
const |
|
inlinenoexcept |
◆ Validate() [1/2]
bool CppSecurity::GoogleAuthenticator::Validate |
( |
size_t |
token, |
|
|
std::string_view |
password, |
|
|
std::string_view |
salt, |
|
|
const CppCommon::Timestamp & |
timestamp = CppCommon::UtcTimestamp() |
|
) |
| const |
Validate the Google Authenticator token over the given user password, unique salt and UTC timestamp.
- Parameters
-
token | - Google Authenticator token |
password | - User password |
salt | - Unique password salt |
timestamp | - UTC timestamp (default is CppCommon::UtcTimestamp()) |
- Returns
- 'true' if the given token is valid, 'false' if the given token is invalid
Definition at line 118 of file google_authenticator.cpp.
◆ Validate() [2/2]
bool CppSecurity::GoogleAuthenticator::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.
- Parameters
-
token | - Google Authenticator token |
secret | - Google Authenticator secret |
timestamp | - UTC timestamp (default is CppCommon::UtcTimestamp()) |
- Returns
- 'true' if the given token is valid, 'false' if the given token is invalid
- Examples
- google_authenticator.cpp.
Definition at line 113 of file google_authenticator.cpp.
The documentation for this class was generated from the following files: