Logo

Cake Planner

Backend

totp_utils.cpp

File Header Information

FieldValue
SPDX CommentTime-based One-Time Password (TOTP) Utilities
SPDX TypeSOURCE
ContributorZHENG Robert
License IDMIT
Filetotp_utils.cpp
DescriptionTime-based One-Time Password (TOTP) Utilities
Version0.15.0
Date2026-01-24
AuthorZHENG Robert (robert@hase-zheng.net)
CopyrightCopyright (c) 2026 ZHENG Robert
LicenseMIT

Table of Contents

API Documentation

namespace utils

utils namespace.


QString TotpUtils::generateSecret()

Generates a random Base32 secret for TOTP.

Returns: The generated secret string.


std::uniform_int_distribution dist(0, 31)

Function implementation.


QString TotpUtils::getProvisioningUri(const QString &userEmail,

Generates the provisioning URI for the QR code.

ParameterDescription
userEmailThe email address of the user.
secretThe Base32 secret.
issuerThe name of the issuer (e.g., "Cake Planner").

Returns: The provisioning URI string.


int64_t TotpUtils::getCurrentTimeStep()

Gets the current time step for TOTP calculation.

Returns: The current time step.


std::vector TotpUtils::base32Decode(const QString &secret)

Decodes a Base32 string into bytes.

ParameterDescription
secretThe Base32 encoded secret.

Returns: A vector of bytes representing the decoded secret.


QString TotpUtils::generateCodeForStep(const std::vector &keyBytes,

Generates a TOTP code for a specific time step.

ParameterDescription
keyBytesThe decoded secret key in bytes.
timeStepThe time step to generate the code for.

Returns: The 6-digit TOTP code as a string.


bool TotpUtils::validateCode(const QString &secret, const QString &code)

Validates a TOTP code against a secret.

ParameterDescription
secretThe Base32 secret.
codeThe TOTP code to validate.

Returns: True if the code is valid, false otherwise.