secure pin entry snippet
@Composable
fun SecurePinEntry() {
val view = LocalView.current
// FLAG_SECURE: no screenshots, no screen recording, blanked in recents.
DisposableEffect(Unit) {
val window = (view.context as Activity).window
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
onDispose { window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
var pin by remember { mutableStateOf("") }
OutlinedTextField(
value = pin,
onValueChange = { if (it.length <= 6 && it.all(Char::isDigit)) pin = it },
label = { Text("PIN") },
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(
// Password keyboard type is treated as sensitive: the IME keeps
// entered digits out of personalized-learning/suggestions.
keyboardType = KeyboardType.NumberPassword,
imeAction = ImeAction.Done
),
// pointerInteropFilter requires @OptIn(ExperimentalComposeUiApi::class).
// Reject taps that arrive while another window sits on top (tap-jacking).
modifier = Modifier.pointerInteropFilter { event ->
val obscured = event.flags and
(MotionEvent.FLAG_WINDOW_IS_OBSCURED or
MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED)
obscured != 0 // true = consume & ignore the event
}
)
}Was this helpful?

