SecurePasswd_MGMT 2026.03.19
A modern, cross-platform password manager and two-factor authenticator (TOTP) designed with state-of-the-art security.
Loading...
Searching...
No Matches
database.h File Reference
#include <stddef.h>
Include dependency graph for database.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  PasswordEntry
 A struct representing a password entry. More...

Functions

int database_open (const char *db_path, const char *password)
 Opens and initializes the database.
void database_close ()
 Closes the database.
PasswordEntrydatabase_get_all_entries (int *count)
 Retrieves all password entries from the database.
PasswordEntrydatabase_search (const char *query, int *count)
 Searches for password entries by service or username.
PasswordEntrydatabase_get_entry_by_identity (const char *service, const char *username)
 Retrieves a password entry by its identity (Service + Username).
PasswordEntrydatabase_get_entry_secure (int id)
 Retrieves a single password entry with ALL details (including secrets) by ID.
int database_rekey (const char *new_password)
 Changes the master password of the database.
int database_add_entry (const PasswordEntry *entry)
 Adds a new password entry to the database.
int database_update_entry (const PasswordEntry *entry)
 Updates an existing password entry in the database.
int database_delete_entry (int id)
 Deletes a password entry from the database by its ID.
void free_password_entries (PasswordEntry *entries, int count)
 Frees a list of PasswordEntry structs.

Function Documentation

◆ database_add_entry()

int database_add_entry ( const PasswordEntry * entry)

Adds a new password entry to the database.

Parameters
entryA pointer to the PasswordEntry to add.
Returns
The ID of the new entry, or -1 on error.

◆ database_close()

void database_close ( )

Closes the database.

◆ database_delete_entry()

int database_delete_entry ( int id)

Deletes a password entry from the database by its ID.

Parameters
idThe ID of the entry to delete.
Returns
0 on success, -1 on error.

◆ database_get_all_entries()

PasswordEntry * database_get_all_entries ( int * count)

Retrieves all password entries from the database.

Parameters
countA pointer to an integer that will be filled with the number of entries.
Returns
A dynamically allocated array of PasswordEntry structs. The caller is responsible for freeing this array and its contents using free_password_entries().

◆ database_get_entry_by_identity()

PasswordEntry * database_get_entry_by_identity ( const char * service,
const char * username )

Retrieves a password entry by its identity (Service + Username).

Parameters
serviceThe name of the service.
usernameThe username for the service.
Returns
A dynamically allocated PasswordEntry struct containing full details, or NULL if not found.

◆ database_get_entry_secure()

PasswordEntry * database_get_entry_secure ( int id)

Retrieves a single password entry with ALL details (including secrets) by ID.

Parameters
idThe ID of the entry to retrieve.
Returns
A dynamically allocated PasswordEntry struct containing full details, or NULL if not found/error. The caller is responsible for freeing this struct using free_password_entry() (to be added) or manual free.

◆ database_open()

int database_open ( const char * db_path,
const char * password )

Opens and initializes the database.

Parameters
db_pathThe path to the database file.
passwordThe master password for the database.
Returns
0 on success, -1 on error.

◆ database_rekey()

int database_rekey ( const char * new_password)

Changes the master password of the database.

Parameters
new_passwordThe new master password.
Returns
0 on success, -1 on error.

◆ database_search()

PasswordEntry * database_search ( const char * query,
int * count )

Searches for password entries by service or username.

Parameters
queryThe search query string.
countA pointer to an integer that will be filled with the number of entries.
Returns
A dynamically allocated array of PasswordEntry structs. The caller is responsible for freeing this array and its contents using free_password_entries().

◆ database_update_entry()

int database_update_entry ( const PasswordEntry * entry)

Updates an existing password entry in the database.

Parameters
entryA pointer to the PasswordEntry to update.
Returns
0 on success, -1 on error.

◆ free_password_entries()

void free_password_entries ( PasswordEntry * entries,
int count )

Frees a list of PasswordEntry structs.

Parameters
entriesThe array of PasswordEntry structs to free.
countThe number of entries in the array.