Face Login

Prerequisites

First, the user has to be an approved customer by having completed the onboarding flow. Check the image below for more information:

Initialize Incode Welcome SDK as described here.

1:N Face Login - Identify a user

1:N Face login is suitable if you would like to identify a user by doing a face scan. This will execute a face match comparison across your entire user database and checks if the face corresponds to any of the approved users.

To execute 1:N Face Login call startFaceLogin method:

Kotlin

IncodeWelcome.getInstance()
    .startFaceLogin(activityContext, SelfieScan.Builder().build(), object : SelfieScanListener {
        override fun onSelfieScanCompleted(selfieScanResult: SelfieScanResult) {
            if (selfieScanResult.status == SelfieScanResult.STATUS_OK) {
                val faceLoginResult = selfieScanResult.faceLoginResult
                if (faceLoginResult != null && faceLoginResult.success) {
                    val customerUUID = faceLoginResult.customerUUID
                    val token = faceLoginResult.token
                    val interviewId = faceLoginResult.interviewId
                    // ...
                } else {
                    val isSpoofAttempt = selfieScanResult.isSpoofAttempt ?: false
                    if (isSpoofAttempt) {
                        // Liveness failed
                    } else {
                        // User's face not found
                    }
                }
            } else {
                // Some of the preconditions for checking liveness failed, check selfieScanResult.status for specific info
            }
        }

override fun onError(error: Throwable) {
            // Some error occurred
        }

override fun onUserCancelled() {
            // User canceled login
        }
    })

Java

IncodeWelcome.getInstance()
    .startFaceLogin(activityContext, new SelfieScan.Builder().build(), new SelfieScanListener() {
        @Override
        public void onSelfieScanCompleted(@NonNull SelfieScanResult selfieScanResult) {
            if (selfieScanResult.status == SelfieScanResult.STATUS_OK) {
                FaceLoginResult faceLoginResult = selfieScanResult.faceLoginResult;
                if (faceLoginResult != null && faceLoginResult.success) {
                    String customerUUID = faceLoginResult.customerUUID;
                    String token = faceLoginResult.token;
                    String interviewId = faceLoginResult.interviewId;
                    // ...
                } else {
                    boolean isSpoofAttempt = selfieScanResult.isSpoofAttempt != null ? selfieScanResult.isSpoofAttempt : false;
                    if (isSpoofAttempt) {
                        // Liveness failed
                    } else {
                        // User's face not found
                    }
                }
            } else {
                // Some of the preconditions for checking liveness failed, check selfieScanResult.status for specific info
            }
        }

@Override
        public void onError(@NonNull Throwable error) {
            // Some error occurred
        }

@Override
        public void onUserCancelled() {
            // User canceled login
        }
    });

1:1 Face Login - Verify the face of a specific user

1:1 Face Login is suitable if you want do a face authentication for a specific user that is already pre-authorized, meaning you already have the customer's UUID and only want to know if this exact person is trying to authenticate.

To execute 1:1 Face Login call startFaceLogin method:

Kotlin

val selfieScanListener = object : SelfieScanListener {
    override fun onSelfieScanCompleted(selfieScanResult: SelfieScanResult) {
        when (selfieScanResult.status) {
            SelfieScanResult.STATUS_OK -> {
                val faceLoginResult = selfieScanResult.faceLoginResult;
                if (faceLoginResult != null && faceLoginResult.success) {
                    val customerUUID = faceLoginResult.customerUUID;
                    val token = faceLoginResult.token;
                    val interviewId = faceLoginResult.interviewId;
                    // ...
                } else {
                    val isSpoofAttempt = selfieScanResult.isSpoofAttempt ?: false;
                    if (isSpoofAttempt) {
                        // Liveness failed
                    } else {
                        // User's face is not similar to previously enrolled face
                    }
                }
            }
            else -> {
                // Some of the preconditions for checking liveness failed, check selfieScanResult.status for specific info
            }
        }
    }

override fun onError(error: Throwable) {
        // Some error occurred
    }

override fun onUserCancelled() {
        // User canceled login
    }
}

// ...

IncodeWelcome.getInstance()
    .startFaceLogin(
        activityContext,
        SelfieScan.Builder().setCustomerUUID("YOUR_CUSTOMER_ID").build(),
        selfieScanListener
    )

Java

IncodeWelcome.getInstance()
    .startFaceLogin(activityContext, new SelfieScan.Builder().setCustomerUUID("YOUR_CUSTOMER_ID").build(), new SelfieScanListener() {
        @Override
        public void onSelfieScanCompleted(@NonNull SelfieScanResult selfieScanResult) {
            if (selfieScanResult.status == SelfieScanResult.STATUS_OK) {
                FaceLoginResult faceLoginResult = selfieScanResult.faceLoginResult;
                if (faceLoginResult != null && faceLoginResult.success) {
                    String customerUUID = faceLoginResult.customerUUID;
                    String token = faceLoginResult.token;
                    String interviewId = faceLoginResult.interviewId;
                    // ...
                } else {
                    boolean isSpoofAttempt = selfieScanResult.isSpoofAttempt != null ? selfieScanResult.isSpoofAttempt : false;
                    if (isSpoofAttempt) {
                        // Liveness failed
                    } else {
                        // User's face is not similar to previously enrolled face
                    }
                }
            } else {
                // Some of the preconditions for checking liveness failed, check selfieScanResult.status for specific info
            }
        }

@Override
        public void onError(@NonNull Throwable error) {
            // Some error occurred
        }

@Override
        public void onUserCancelled() {
            // User canceled login
        }
    });

Face Login result

The resulting SelfieScanResult object will have the following:

Login parametrization

By default, Face Login will complete a liveness check and face match on the server. You can perform on-device liveness check and face match for offline use-cases.

To switch to on-device liveness and on-device face recognition include:

  1. In your module-level app/build.gradle, add an additional Incode dependency:

Groovy

dependencies {
    ...
    implementation 'com.incode.sdk:model-liveness-detection:3.2.1'
    implementation 'com.incode.sdk:model-face-recognition:3.5.1'
}

Kotlin

dependencies {
    ...
    implementation("com.incode.sdk:model-liveness-detection:3.2.1")
    implementation("com.incode.sdk:model-face-recognition:3.5.1")
}
  1. Specify FaceAuthMode.LOCAL when creating SelfieScan module

Kotlin

val selfieScan = SelfieScan.Builder()
    .setFaceAuthMode(SelfieScan.FaceAuthMode.LOCAL)
    .build()

Java

SelfieScan selfieScan = new SelfieScan.Builder()
    .setFaceAuthMode(SelfieScan.FaceAuthMode.LOCAL)
    .build();

Note: SelfieScan.FaceAuthMode.LOCAL can work only in 1:1 mode and if the user's face template is already saved locally in the device. Templates get saved during successful onboarding or by using the allowFaceAuthModeFallback parameter (please check explanation below).

Other parameters to consider: