CppSecurity  1.1.1.0
C++ Security Library
Public Member Functions | List of all members
CppSecurity::GoogleAuthenticator Class Reference

Google Authenticator. More...

#include <google_authenticator.h>

Public Member Functions

 GoogleAuthenticator (size_t secret_length=12, size_t pin_length=6)
 Initialize Google Authenticator with required parameters. More...
 
 GoogleAuthenticator (const GoogleAuthenticator &)=default
 
 GoogleAuthenticator (GoogleAuthenticator &&)=default
 
 ~GoogleAuthenticator ()=default
 
GoogleAuthenticatoroperator= (const GoogleAuthenticator &)=default
 
GoogleAuthenticatoroperator= (GoogleAuthenticator &&)=default
 
size_t secret_length () const noexcept
 Get the secret length. More...
 
size_t pin_length () const noexcept
 Get the pin length. More...
 
std::string GenerateSalt () const
 Generate the unique password salt. More...
 
std::password GenerateSecret (std::string_view password) const
 Generate the Google Authenticator secret from the given user password. More...
 
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. More...
 
std::password GenerateURL (std::string_view identifier, std::string_view secret) const
 Generate the Google Authenticator URL. More...
 
std::password GenerateQRCodeLink (std::string_view url, size_t width=100, size_t height=100) const
 Generate the Google Authenticator QR Code link. More...
 
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. More...
 
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. More...
 
bool 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. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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]

CppSecurity::GoogleAuthenticator::GoogleAuthenticator ( const GoogleAuthenticator )
default

◆ GoogleAuthenticator() [3/3]

CppSecurity::GoogleAuthenticator::GoogleAuthenticator ( GoogleAuthenticator &&  )
default

◆ ~GoogleAuthenticator()

CppSecurity::GoogleAuthenticator::~GoogleAuthenticator ( )
default

Member Function Documentation

◆ 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

Generate the unique password salt.

Returns
Unique password salt

Definition at line 35 of file google_authenticator.cpp.

◆ GenerateSecret() [1/2]

std::password CppSecurity::GoogleAuthenticator::GenerateSecret ( std::string_view  password) const

Generate the Google Authenticator secret from the given user password.

Parameters
password- User password
Returns
Generated Google Authenticator secret
Examples
google_authenticator.cpp.

Definition at line 42 of file google_authenticator.cpp.

◆ 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]

GoogleAuthenticator& CppSecurity::GoogleAuthenticator::operator= ( const GoogleAuthenticator )
default

◆ operator=() [2/2]

GoogleAuthenticator& CppSecurity::GoogleAuthenticator::operator= ( GoogleAuthenticator &&  )
default

◆ pin_length()

size_t CppSecurity::GoogleAuthenticator::pin_length ( ) const
inlinenoexcept

Get the pin length.

Definition at line 51 of file google_authenticator.h.

◆ secret_length()

size_t CppSecurity::GoogleAuthenticator::secret_length ( ) const
inlinenoexcept

Get the secret length.

Definition at line 49 of file google_authenticator.h.

◆ 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: