Skip to content

gowtham-32112/PasswordlessAuthApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PasswordlessAuthApp

A local-logic-only Android application demonstrating passwordless authentication using Login, OTP, and Session screens. Built with Kotlin and Jetpack Compose.

Architecture

The application follows the MVVM (Model-View-ViewModel) architecture:

  • Data Layer: OtpManager handles OTP generation, storage (in-memory Map), and validation. It acts as the "Backend" simulation.
  • ViewModel Layer: AuthViewModel manages the UI state (AuthState) and business logic (timers, coordinating with OtpManager).
  • UI Layer: Jetpack Compose screens (LoginScreen, OtpScreen, SessionScreen) observe the state and render accordingly. Navigation is handled by swapping composables based on the current state in MainActivity.

Data Structures

  • OtpData: Stores otp (String), expiryTime (Long), and attempts (Int).
  • otpStore: A mutableMapOf<String, OtpData> in OtpManager creates a transient in-memory database keyed by email.

Analytics

Timber is used for logging as per requirements. It is initialized in PasswordlessAuthApplication. Logged events include:

  • OTP generated
  • OTP validation success/failure/expiry
  • Logout events

Logic & Edge Cases

  • OTP Expiry: OTPs are valid for 60 seconds. OtpManager checks System.currentTimeMillis() against expiryTime.
  • Attempts: Max 3 attempts are allowed. Exceeding this blocks validation until a new OTP is requested.
  • Session Timer: SessionScreen displays the live duration (mm:ss), updated every second via a Coroutine in AuthViewModel.
  • Rotation: UI state inputs (email, otp input) use rememberSaveable to survive configuration changes. The session timer survives in the ViewModel.

Setup & Build

  1. Open the project in Android Studio.
  2. Sync Gradle with the project files.
  3. Run on an emulator or physical device.
  4. Check Logcat (filter by "Timber" or "PasswordlessAuth") to see the generated OTPs for testing.

How to Test

  1. Login: Enter an email and click "Send OTP".
  2. Get OTP: Check Android Studio Logcat for "OTP generated for : <123456>".
  3. Enter OTP:
    • Success: Enter the correct code. You go to the Session screen.
    • Fail: Enter incorrect code. Error message shown.
    • Wait: Wait >60s. Error message "OTP Expired".
    • Retry: Enter wrong code 3 times. Error message "Too many attempts".
  4. Session: Observe the timer counting up. Click Logout to reset.

About

Create a native Android application using Kotlin and Jetpack Compose that implements a passwordless authentication flow (Login -> OTP -> Session) with local OTP management and Timber logging.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages