> ## Documentation Index
> Fetch the complete documentation index at: https://docs.escrivalimited.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication Lifecycle

To ensure a highly secure and customized experience, the Sasini App utilizes a strict, multi-step identity pipeline. Whether you are registering for the first time, establishing a new session, or updating your credentials, our systems operate on a **Zero-Trust Architecture**. This infrastructure actively monitors for anomalies and requires explicit verification at every stage to guarantee that your harvest records and financial payouts remain permanently protected.

***

## Phase 1: Registration & Onboarding

### 1. Localization & Language Selection

The Sasini ecosystem operates across diverse demographics. To ensure accurate data entry and seamless navigation, the onboarding process begins with interface localization.

<Steps>
  <Step title="Launch the Application">
    The onboarding process begins with interface localization i.e. Selection of preferred language and identity selection to determine the user's specific permissions.
    The welcome screen presents two distinct pathways:
    Sasini Farmer: For official tea/coffee producers.
    Guest / Buyer: For marketplace participants and external stakeholders.

    <Accordion title="Backend Security: Zero-Trust Handshake" icon="server">
      **What happens under the hood:** The moment the app launches, it initiates a secure "handshake" with the Sasini servers. We assume every connection is potentially hostile. The backend instantly scans the connection for SSL/TLS 1.3 encryption certificates to ensure the network hasn't been compromised before allowing the app to load.
    </Accordion>
  </Step>

  <Step title="Select Preferred Language">
    Users must select between **English**, **Swahili**, **French**, or **German**. This selection executes a global state update, translating all UI components and instructions.
  </Step>
</Steps>

<div style={{ height: '20px' }} />

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/Bc_j5YiuWgVjPkB-/images/language-selection.jpeg?fit=max&auto=format&n=Bc_j5YiuWgVjPkB-&q=85&s=ed5ed33db9a34bc05b7e5efb31769034" alt="Language Selection Screen" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="337" height="735" data-path="images/language-selection.jpeg" />
</div>

<div style={{ height: '20px' }} />

<Tip>
  **Post-Registration Adjustments:** If you select the wrong language during onboarding, you can always update your localization preferences later from the primary Settings menu.
</Tip>

### 2. Farmer Validation Protocol

Account creation is strictly limited to authorized personnel. Before establishing a profile, the system must verify the user against the central Sasini factory database.

<Steps>
  <Step title="Input Farmer ID and other credentials">
    The user is required to input their officially registered **Sasini Farmer ID**, **National ID** and **Phone Number**. This establishes the crucial link between the digital account and real-world delivery records.
    Guests and Buyers bypass the ID validation and proceed directly to email registration (Account Creation Phase).

    <Accordion title="Backend Security: Parameterized Query Execution" icon="server">
      **What happens under the hood:** To absolutely prevent SQL Injection, the backend sanitizes the Farmer ID, National ID and Phone Number using parameterized queries. It strips the input of executable code before querying the encrypted database. Invalid IDs throw a generic `Validation Failed`.
    </Accordion>
  </Step>

  <Step title="System Verification">
    If verified, the app retrieves the farmer's foundational profile data and authorizes progression to the security setup phase. If invalid, the process is securely halted.
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/f40gPCbcaplZPLSn/images/farmer-validation.jpeg?fit=max&auto=format&n=f40gPCbcaplZPLSn&q=85&s=f9003a1191a77610a9313447f8432446" alt="Farmer ID Validation Screen" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/farmer-validation.jpeg" />
</div>

<Tip>
  **Locating Your ID:** Your official Farmer ID is printed on your physical delivery receipts and factory registration documents. If you have misplaced it, please contact your local Sasini extension officer.
</Tip>

### 3. Account Creation & MFA Setup

Following validation, the user must secure their digital identity using Multi-Factor Authentication (MFA) parameters.

<Steps>
  <Step title="Enter Credentials">
    The user registers their primary **Email Address** and establishes a secure **Password** for future authentication.

    <Accordion title="Backend Security: Backend Security: Encryption & Password Protection" icon="server">
      **What happens under the hood:** When the user taps “Submit,” the password is encrypted locally on the device before transmission, so even if intercepted over public Wi-Fi it appears as an unreadable string of randomized characters. Sasini never stores actual passwords—the backend converts them using a salted cryptographic hashing algorithm, creating a one-way hash that makes stolen database data useless to attackers. 🔐
    </Accordion>
  </Step>

  <Step title="Enforce Password Policies">
    To protect sensitive financial ledgers, the platform strictly enforces robust password complexity requirements. The password must contain:

    * At least one **uppercase letter**
    * At least one **lowercase letter**
    * At least one **number**
    * At least one **special symbol** (e.g., @, #, \$, !)
  </Step>

  <Step title="Legal Agreements">
    Users must formally acknowledge and accept the **Terms of Use** and **Privacy Policy** to proceed.
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/NhUQiugTrJ1QgDnT/images/registration-details.jpeg?fit=max&auto=format&n=NhUQiugTrJ1QgDnT&q=85&s=179c124e227d2f67d688710db68e9086" alt="Registration Details Screen" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/registration-details.jpeg" />
</div>

<Tip>
  **Credential Security:** Avoid using easily guessable information such as your name or birth year. For optimal security, consider using a dedicated Password Manager application to generate and store your credentials.
</Tip>

### 4. Email Link Verification

To eliminate fraudulent registrations and guarantee secure communication channels, the platform mandates a rigorous email verification loop.

<Accordion title="Backend Security: Secure Token & Link Protection" icon="server">
  **What happens under the hood:** Verification links contain cryptographically secure tokens generated using a CSPRNG. These tokens are unique, tied to the request context, and expire quickly. Once used, the system immediately invalidates the token to prevent replay attacks or reuse of old links.
</Accordion>

<Steps>
  <Step title="Dispatch Verification">
    Upon submitting the registration payload, the server dispatches a secure, time-sensitive verification link to the registered email address.
  </Step>

  <Step title="Action Required">
    The user must navigate to their email client and click the embedded secure link. This verifies cryptographic ownership of the designated address.
  </Step>

  <Step title="Resend Protocol">
    To prevent server spamming, if the email is not received immediately, the system enforces a mandatory **60-second cooldown** before a new verification payload can be requested.
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/f40gPCbcaplZPLSn/images/email-verification.jpeg?fit=max&auto=format&n=f40gPCbcaplZPLSn&q=85&s=7a090161de06cdcc746de0a1c1bd605f" alt="Email Verification Prompt" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/email-verification.jpeg" />
</div>

<Tip>
  **Troubleshooting:** If you do not see the verification email in your primary inbox, please ensure you check your 'Spam' or 'Junk' folders, as strict security emails are occasionally filtered by providers like Gmail or Yahoo.
</Tip>

### 5. Profile Finalization & Dashboard

Upon successful token verification, the backend commits the registration data and provisions the user's secure environment.

<Accordion title="Backend Security: Secure Sessions & Audit Logging" icon="server">
  **What happens under the hood:** After verification, the server issues a secure **JWT session token** used to authenticate all user actions, with frequent rotation to limit hijacked sessions. The event is also recorded in an **immutable, write-only audit log** to ensure permanent traceability and ongoing security monitoring.
</Accordion>

<Steps>
  <Step title="Data Synchronization">
    The user's Unique Digital ID is finalized, and the application securely syncs historical harvest data, delivery logs, and payment ledgers from the factory servers.
  </Step>

  <Step title="Enter the Dashboard">
    The user (farmer) is routed directly to the main **Dashboard**, while the Guest/Buyers are routed to a similar dashboard only that high-stakes modules such as deliveries and payments are injected after the user role is validated as a registered farmer finalizing the onboarding sequence.
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/7qc8vOi6GuaObtOI/images/main-dashboard.jpeg?fit=max&auto=format&n=7qc8vOi6GuaObtOI&q=85&s=e9590ab88fd06167df17fbd4dd3870c9" alt="Sasini App Main Dashboard" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="404" height="871" data-path="images/main-dashboard.jpeg" />
</div>

***

## Phase 2: Login & Access

Subsequent access to the platform requires strict authentication. While streamlined for the user, the backend executes complex risk analyses during every login attempt.

### 1. Credential Submission

<Steps>
  <Step title="Sign In">
    The user inputs their verified Email Address and Password into the authentication portal.

    <Accordion title="Backend Security: Constant-Time Hash Comparison" icon="server">
      **What happens under the hood:** The backend retrieves the hashed password and applies the same algorithm to the newly typed password. To prevent "Timing Attacks," the server uses a constant-time comparison, taking the exact same microsecond to respond whether the password is right or wrong.
    </Accordion>
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/bxN5Sc1kw2hf3k3i/images/login-screen.jpeg?fit=max&auto=format&n=bxN5Sc1kw2hf3k3i&q=85&s=d7d5ce7a12bb3f742b1cd080d6e08b61" alt="Sasini App Login Screen" style={{ maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/login-screen.jpeg" />
</div>

***

## Phase 3: Account Recovery & Settings

To accommodate device sharing and administrative updates, the Sasini App provides a comprehensive, highly secure credential management suite.

### 1. Session Termination (Logging Out)

Users are strongly encouraged to terminate their sessions when accessing the platform via shared hardware.

<Steps>
  <Step title="Initiate Logout">
    Navigate to the Settings profile and tap **Log Out**. The system will present a confirmation dialog to prevent accidental session termination.
  </Step>
</Steps>

<Accordion title="Backend Security: JWT Revocation & Blacklisting" icon="server">
  **What happens under the hood:** Clicking "Log Out" does not just clear the screen. The frontend deletes the secure token from local storage, while the backend actively adds that specific session token to a cryptographic "Blacklist." Even if a hacker managed to copy the token right before the user logged out, the server will reject it entirely.
</Accordion>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/DeBIWccfQxCUGZgK/images/logout-dialog.jpeg?fit=max&auto=format&n=DeBIWccfQxCUGZgK&q=85&s=df13e5043c2c0de086ccce782edd4aaa" alt="Logout Confirmation Dialog" style={{ maxWidth: '300px', margin: '1rem auto', borderRadius: '12px' }} width="456" height="275" data-path="images/logout-dialog.jpeg" />
</div>

<Tip>
  **Device Management:** If you ever lose your mobile device, please contact Sasini Support immediately. Our administrators can manually revoke all active sessions remotely, securing your account instantly.
</Tip>

### 2. Account Recovery (Forgot Password)

In the event of lost credentials, users can securely re-establish access without compromising historical data.

<Steps>
  <Step title="Request Reset">
    Select **Forgot Password** from the primary authentication screen and provide the registered email address.
  </Step>

  <Step title="Secure Email Link">
    The system dispatches a cryptographic reset link. To minimize the window of vulnerability, this link automatically expires in exactly **15 minutes**.

    <Accordion title="Backend Security: Anti-Enumeration & Signed URLs" icon="server">
      **What happens under the hood:** To prevent hackers from guessing which emails are registered, the backend will *always* say "If this email exists, a reset link has been sent," regardless of whether the email is valid. The link sent contains a securely signed URL payload that can only be decrypted by our servers.
    </Accordion>
  </Step>

  <Step title="Create New Credentials">
    The user clicks the authorized link and submits a new password adhering to the platform's strict complexity parameters.
  </Step>
</Steps>

<div align="center">
  <img src="https://mintcdn.com/escrivalimited/DeBIWccfQxCUGZgK/images/forgot-password-page.jpeg?fit=max&auto=format&n=DeBIWccfQxCUGZgK&q=85&s=1c6c6a6476a2b84f28fc6a2b2830c6e0" alt="Forgot Password Page" style={{width: '100%', maxWidth: '300px', margin: '0 auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/forgot-password-page.jpeg" />
</div>

### 3. The Strict Re-authentication Loop

When a user actively chooses to update their password from within the application, the system enforces a strict re-authentication loop. This architectural decision prevents unauthorized password modifications if an unlocked device is compromised.

<Steps>
  <Step title="Initiate Change">
    Upon selecting **Change Password** within the profile settings, the application deliberately and immediately terminates the active session.
  </Step>

  <Step title="Re-Authenticate">
    The user is routed to the login portal and must successfully authenticate using their *current* credentials, verifying physical ownership of the device.
  </Step>

  <Step title="Identity Verification">
    Following successful authentication, the system intercepts the standard routing and presents a verification dialog: *"Identity Verified. Click Continue to change your password."*

    <div align="center">
      <img src="https://mintcdn.com/escrivalimited/DeBIWccfQxCUGZgK/images/change-password-dialog.jpeg?fit=max&auto=format&n=DeBIWccfQxCUGZgK&q=85&s=06181c3cd069b52e7873261eda83e630" alt="Identity Verified Dialog" style={{ width: '100%', maxWidth: '300px', margin: '1rem auto', borderRadius: '12px' }} width="483" height="386" data-path="images/change-password-dialog.jpeg" />
    </div>
  </Step>

  <Step title="Update & Auto-Logout">
    The user inputs the new parameters. Upon successful submission, the system executes the update and **automatically terminates the session a second time**.

    <div align="center">
      <img src="https://mintcdn.com/escrivalimited/DeBIWccfQxCUGZgK/images/change-password-page.jpeg?fit=max&auto=format&n=DeBIWccfQxCUGZgK&q=85&s=d191b613bb0b150494b065261445dee7" alt="Enter New Password Page" style={{ width: '100%', maxWidth: '300px', margin: '1rem auto', borderRadius: '12px' }} width="715" height="1600" data-path="images/change-password-page.jpeg" />
    </div>
  </Step>

  <Step title="Final Verification">
    The user logs in with the newly established credentials, verifying database synchronization.

    <Accordion title="Backend Security: Cryptographic Salt Rotation" icon="server">
      **What happens under the hood:** When the password is changed, the backend doesn't just hash the new password; it generates a brand new cryptographic "Salt" (a random data string) and destroys the old one. It also instantly revokes all active sessions on any other devices, forcing anyone using the account to re-authenticate immediately.
    </Accordion>
  </Step>
</Steps>

<Tip>
  **Proactive Security:** For maximum account integrity, cybersecurity standards recommend updating your password every 90 to 120 days.
</Tip>

### 4. Account Deactivation

Users maintain full autonomy over their digital footprint and may request account deactivation at any time via the Security Settings.

<Warning>
  **Critical Notice:** Account deactivation is **reversible** whereas Account deletion is **irreversible**. Historical harvest weights, payment ledgers, and AI-driven agricultural insights cannot be recovered once purged.
</Warning>

<Steps>
  <Step title="Initiate Deactivation">
    The user selects **Deactivate Account** and must verify their intent via MFA to prevent accidental deletion.

    <div align="center">
      <img src="https://mintcdn.com/escrivalimited/DeBIWccfQxCUGZgK/images/deactivate-account-dialog.jpeg?fit=max&auto=format&n=DeBIWccfQxCUGZgK&q=85&s=cd66e659fcc970711398acd19f43f3f9" alt="Account Deactivation Dialog" style={{width: '100%', maxWidth: '300px', margin: '1rem auto', borderRadius: '12px' }} width="468" height="391" data-path="images/deactivate-account-dialog.jpeg" />
    </div>
  </Step>

  <Step title="Grace Period">
    For **Deleted** accounts, the account is transitioned into a suspended state for 30 days. But for **Deactivated** accounts, the user may rescind the deactivation request simply by executing a successful login or Contacting the Support team for activation purposes.
  </Step>

  <Step title="Permanent Purge">
    Following the 30-day window, the system executes a permanent data purge.

    <Accordion title="Backend Security: Cascading Data Anonymization" icon="server">
      **What happens under the hood:** To maintain the integrity of Sasini's overall agricultural and financial analytics while complying with data protection laws, the backend performs a "Cascading Anonymization." The user's personal identifiable information (PII) like Name, Email, and Phone Number are permanently deleted and replaced with randomized string values. Their harvest weights and dates remain for corporate accounting, but they can mathematically never be traced back to the individual farmer again.
    </Accordion>
  </Step>
</Steps>
