Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica
Skip to main content

create_account

Function create_account 

Source
pub async fn create_account(
    users_db: &Database,
    instance: &Instance,
    username: impl AsRef<str>,
    password: &str,
) -> Result<(String, AccountInfo, PrivateKey)>
Expand description

Create a new account

This function:

  1. Optionally hashes the account’s password (if provided)
  2. Generates a device keypair for the account
  3. Creates the portable Account database (no private keys)
  4. Registers AccountInfo in native local storage with a login UUID
  5. First-admin bootstrap: if no instance admin exists yet in _users.auth_settings, promotes this account by adding their pubkey as Admin(0) to the instance-admin system DBs (_users and _databases). Subsequent accounts land as non-admins.

§Arguments

  • users_db - The _users system database
  • instance - The Instance handle
  • username - Unique username for login
  • password - Password string, including empty; all logins use encrypted bundles.

§Returns

A tuple of (login_id, AccountInfo, root_private_key). The private key is the one just generated for this account; callers (e.g. Instance::create_backend or InstanceAdmin::create_account) can hand it straight to [build_account_session] to materialise a logged-in AccountSession without re-decrypting the key from storage.