Skip to content

Passcode Creation Screen

The Passcode Creation Screen screen creates the passcode that protects the app.

Passcode Creation Screen

Definition

@Composable
fun SetPasscodeScreen(
    rules: List<PasscodeRule> = listOf(PasscodeRule(PasscodeRuleType.MIN_LEN, data = 8)),
    setPasscodeScreenSettings: SetPasscodeScreenSettings? = null,
    currentPasscode: String? = null,
    validate: ((String) -> Boolean)? = null,
    skipButtonClickListener: ViewClickListener? = null,
    backButtonClickListener: ViewClickListener? = null,
    nextButtonClickListener: ((String) -> Unit),
) { ... }

The 'Skip for now' button appears only if you provide a skipButtonClickListener. In the onboarding flow, this button is visible if the application is a single-user profile app and the passcode policy permits skipping the passcode. If the current user data store already has passcode protection, the button remains hidden. In the change passcode flow, even if the original data store isn't passcode protected, the button won't appear. This is because it functions the same as canceling the flow. In this case, you can use the system back button to cancel the flow.

data class SetPasscodeScreenSettings(
    @param:StringRes val title: Int = R.string.set_passcode_screen_title,
    @param:StringRes val description: Int = R.string.set_passcode_screen_desc,
    @param:StringRes val passcodeLabel: Int = R.string.label_passcode,
    @param:StringRes val passcodePlaceholder: Int = R.string.set_passcode_screen_passcode_placeholder,
    @param:StringRes val nextButtonCaption: Int = R.string.label_next,
    @param:StringRes val backButtonCaption: Int = R.string.label_back,
    @param:StringRes val skipButtonCaption: Int = R.string.label_skip_for_now,
    @param:StringRes val samePasscodeErrorMessage: Int = R.string.set_passcode_screen_error_same,
    @param:StringRes val customValidationFailMessage: Int = R.string.set_passcode_screen_error_custom_validation_fail,
    @param:StringRes val historyViolateErrorMessage: Int = R.string.set_passcode_screen_error_history_violation,
    val illustrationSettings: IllustrationSettings = IllustrationSettings(
        iconId = com.sap.cloud.mobile.fiori.theme.R.drawable.img_sap_passwords
    ),
    val stringProvider: SetPasscodeStringProvider? = null
) : BaseScreenSettings

data class PasscodeRule(
    val type: PasscodeRuleType,
    val valid: Boolean = false,
    val data: Int? = 0
) { ... }

enum class PasscodeRuleType {
    MIN_LEN,
    REQ_LOWER_CASE,
    REQ_UPPER_CASE,
    MIN_UNIQUE_CHARS,
    REQ_DIGITAL,
    REQ_SPECIAL_CHAR
}

PasscodeRuleType defines all the predefined rules. Based on the current passcode policy settings, the rules argument could contain some of the validation rules. For the predefined rules, the screen itself would validate the input while the user types. Use the validate argument for additional validation logic. The Next button will be enabled only if the passcode can pass all the validation rules, including the custom validation logic.

Use currentPasscode in the case of the user changing the passcode and the old passcode should not be used.

Example

val rules = mutableListOf<PasscodeRule>()
    val policy = passcodePolicy
    val currentPasscode = "hello_world"

    rules.add(PasscodeRule(type = PasscodeRuleType.MIN_LEN, data = policy.minLength))
    if (policy.lowerRequired) rules.add(PasscodeRule(type = PasscodeRuleType.REQ_LOWER_CASE))
    if (policy.upperRequired) rules.add(PasscodeRule(type = PasscodeRuleType.REQ_UPPER_CASE))
    if (policy.uniqueCharNumber > 0)
        rules.add(
            PasscodeRule(
                type = PasscodeRuleType.MIN_UNIQUE_CHARS,
                data = policy.uniqueCharNumber
            )
        )
    if (policy.digitRequired) rules.add(PasscodeRule(type = PasscodeRuleType.REQ_DIGITAL))
    if (policy.specialCharRequired) rules.add(PasscodeRule(type = PasscodeRuleType.REQ_SPECIAL_CHAR))
    SetPasscodeScreen(
        rules = rules.toList(),
        currentPasscode = currentPasscode,
        validate = {
            myValidationLogic(it)
        }
    ) { code ->
        //handle the code and navigate to the passcode verification step.
    }

Last update: October 29, 2025