171{
173
174 switch (i)
175 {
177 {
179 if (result) do
180 {
181 Field* fields = result->Fetch();
182 if (fields[1].IsNull())
183 continue;
184
186 std::vector<uint8> totpSecret = fields[1].
Get<
Binary>();
187
188 if (hadOldSecret)
189 {
190 if (!oldSecret)
192
194 if (!success)
196 }
197
198 if (newSecret)
200
202 updateStmt->SetData(0, totpSecret);
203 updateStmt->SetData(1, id);
204 trans->Append(updateStmt);
205 } while (result->NextRow());
206
207 break;
208 }
209 default:
210 return std::string("Unknown secret index - huh?");
211 }
212
213 if (hadOldSecret)
214 {
216 deleteStmt->SetData(0, i);
217 trans->Append(deleteStmt);
218 }
219
220 if (newSecret)
221 {
225 if (!hash)
226 return std::string("Failed to hash new secret");
227
229 insertStmt->SetData(0, i);
230 insertStmt->SetData(1, *hash);
231 trans->Append(insertStmt);
232 }
233
235 return {};
236}
std::uint32_t uint32
Definition: Define.h:107
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition: LoginDatabase.h:120
@ LOGIN_INS_SECRET_DIGEST
Definition: LoginDatabase.h:116
@ LOGIN_DEL_SECRET_DIGEST
Definition: LoginDatabase.h:117
std::vector< uint8 > Binary
Definition: Field.h:41
@ SECRET_TOTP_MASTER_KEY
Definition: SecretMgr.h:31
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
static constexpr std::size_t KEY_SIZE_BYTES
Definition: AES.h:31
static Optional< std::string > Hash(std::string const &password, BigNumber const &salt, uint32 nIterations=DEFAULT_ITERATIONS, uint32 kibMemoryCost=DEFAULT_MEMORY_COST)
Definition: Argon2.cpp:21
Definition: BigNumber.h:29
void SetRand(int32 numbits)
Definition: BigNumber.cpp:71
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113