UX4G Logo
Components

Biometric Verification

Aadhaar e-KYC face liveness, iris scan, and fingerprint verification flow with camera overlay, passive liveness checks, and RD Service integration

The UX4G Biometric Verification Flow provides a standardized, secure biometric authentication interface for Indian government mobile applications (Aadhaar e-KYC, Face RD, fingerprint, and iris scans). It guides citizens through passive liveness detection, lighting checks, and seamless backend identity verification with automatic fallback options.

Key Capabilities

  • Aadhaar Face RD & e-KYC Support: Direct integration hooks for UIDAI-compliant Registered Device (RD) face and biometric services.
  • Automated Quality Checks: Built-in validation for ambient lighting (enableLightingCheck), eye-blink detection (enableBlinkCheck), and face oval alignment.
  • Anti-Spoof Passive Liveness: Built-in 3D depth and facial motion liveness verification (enableLiveness) preventing photo and video playback spoofing.
  • Retry & Lockout Management: Configurable maximum attempts (maxAttempts) with automatic fallback to OTP-based alternate verification (onAlternateVerify).
  • Standardized Result Models: Returns structured BiometricVerificationResult payloads and granular BiometricFailureReason error codes.

Import from:

import com.ux4g.designsystemv1.components.biometric.*

Interactive Preview

Ux4gBiometricVerificationFlowJetpack Compose
UX4G Biometric Verification Preview

Complete Kotlin Implementation

1. Production Aadhaar e-KYC Verification Flow

This example demonstrates how to integrate Ux4gBiometricVerificationFlow into a citizen onboarding or pension disbursement screen with coroutine-based RD service authentication and OTP fallback:

BiometricAuthenticationScreen.kt
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.biometric.*
import com.ux4g.designsystemv1.components.buttons.Ux4gButton
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@Composable
fun CitizenKycVerificationScreen(
    onVerificationComplete: (String) -> Unit,
    onFallbackToOtp: () -> Unit
) {
    var isFlowActive by remember { mutableStateOf(false) }
    var errorMessage by remember { mutableStateOf<String?>(null) }

    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(16.dp),
            modifier = Modifier.padding(24.dp)
        ) {
            Text(
                text = "Pension Life Certificate (Jeevan Pramaan)",
                style = MaterialTheme.typography.titleLarge
            )
            Text(
                text = "Complete your annual biometric face verification to continue receiving monthly pension credits.",
                style = MaterialTheme.typography.bodyMedium
            )

            errorMessage?.let { error ->
                Text(
                    text = error,
                    color = MaterialTheme.colorScheme.error,
                    style = MaterialTheme.typography.bodySmall
                )
            }

            Ux4gButton(
                text = "Start Face Verification",
                onClick = {
                    errorMessage = null
                    isFlowActive = true
                }
            )
        }

        // Biometric Face Capture Modal Overlay
        if (isFlowActive) {
            Ux4gBiometricVerificationFlow(
                onVerify = { capturedFrameBytes ->
                    // Perform async network verification against Aadhaar RD backend
                    withContext(Dispatchers.IO) {
                        callAadhaarFaceAuthApi(capturedFrameBytes)
                    }
                },
                enableBlinkCheck = true,
                enableLightingCheck = true,
                enableLiveness = true,
                maxAttempts = 3,
                onSuccess = { result ->
                    isFlowActive = false
                    result.userId?.let { uid -> onVerificationComplete(uid) }
                },
                onFailure = { failureReason, description ->
                    when (failureReason) {
                        BiometricFailureReason.MaxAttemptsExceeded -> {
                            isFlowActive = false
                            errorMessage = "Maximum attempts exceeded. Please verify using Aadhaar OTP."
                        }
                        BiometricFailureReason.PoorLighting -> {
                            errorMessage = "Lighting is too low. Please move to a brighter area."
                        }
                        else -> {
                            errorMessage = description ?: "Verification failed. Please try again."
                        }
                    }
                },
                onAlternateVerify = {
                    isFlowActive = false
                    onFallbackToOtp()
                },
                onDismiss = {
                    isFlowActive = false
                }
            )
        }
    }
}

// Simulated backend API call
suspend fun callAadhaarFaceAuthApi(payload: ByteArray): BiometricVerificationResult {
    // Replace with actual UIDAI / Face RD service SDK invocation
    return BiometricVerificationResult(
        success = true,
        userId = "UIDAI-9842-8841-2041",
        maskedName = "Aarav Sharma",
        confidenceScore = 0.96f,
        timestamp = System.currentTimeMillis()
    )
}

Parameters & API Reference

1. Ux4gBiometricVerificationFlow Composable

PropTypeDescriptionDefault
onVerify *suspend (ByteArray) -> BiometricVerificationResultAsync suspension callback invoked with captured camera biometric byte payload for backend matching.—
onSuccess *(BiometricVerificationResult) -> UnitCallback executed upon successful biometric identity confirmation.—
onFailure *(BiometricFailureReason, String?) -> UnitCallback executed when a capture attempt fails or maximum attempts are exceeded.—
modifierModifierCompose layout modifier applied to the camera viewport container.Modifier
onDismiss(() -> Unit)?Callback triggered when the citizen taps the close/cancel button.null
onAlternateVerify(() -> Unit)?Callback triggered when the citizen chooses an alternate method (e.g., OTP authentication).null
enableBlinkCheckBooleanEnforces active eye-blink detection during facial capture for liveness proof.true
enableLightingCheckBooleanValidates ambient lighting threshold and shows visual guidance if too dark.true
enableLivenessBooleanEnables full 3D facial motion and depth anti-spoof verification.true
maxAttemptsIntMaximum permitted failed capture attempts before triggering lockout.3

2. BiometricVerificationResult Data Model

Returned by onVerify and passed into onSuccess upon identity validation.

FieldTypeDescriptionDefault
success *Booleantrue if identity matching succeeded against the RD backend, false otherwise.—
userIdString?Unique government citizen identifier token (e.g., "GOV-UID-9842").null
maskedNameString?Masked citizen name returned from e-KYC (e.g., "Aarav Sharma").null
confidenceScoreFloat?Biometric match accuracy confidence score (0.0f to 1.0f).null
timestampLongUnix timestamp in milliseconds when the verification succeeded.System.currentTimeMillis()

3. BiometricFailureReason Enum

Categorized error states passed to onFailure(reason, message) for granular user guidance.

ReasonError CodeDescriptionRecommended Citizen Guidance
FaceNotDetectedFACE_OUT_OF_BOUNDSFace is not centered inside the oval guide overlay."Please center your face inside the green oval frame."
PoorLightingINSUFFICIENT_LIGHTAmbient illumination is below the minimum threshold."Move to a brighter area and avoid backlighting."
LivenessFailedLIVENESS_CHECK_FAILEDEye blink or depth movement was not detected."Hold the camera steady and blink naturally when prompted."
MatchMismatchBIOMETRIC_MISMATCHCaptured biometrics do not match Aadhaar registry records."Biometrics do not match. Please retry or verify via OTP."
TimeoutCAPTURE_TIMEOUTCapture session exceeded the permissible response time."Session timed out. Tap retry to start again."
MaxAttemptsExceededLOCKOUT_LIMITCitizen reached maxAttempts consecutive failures."Maximum attempts exceeded. Please authenticate with OTP."

On this page