Skip to content

OzolsUgis/FingerprintSecurityNoteApp

Repository files navigation

Fingerprint Security Note App

Contains
  1. About Project
  2. Usage
  3. Contacts

About Project

Fingerprint security note app is a simple note application which allows you to save your notes under the highest security there is - biometrics, in this case fingerprint. In this project highest emphasis is on implementing fingerprint reader. Saving notes in local database is realy basic. In this little project I tried to implement clean architecture

Built With

This application is built in Android Studio version 2020.3.1 (Artic Fox) using :

Usage

Code Samples

  • This is fingerprint request launching function it only shows when there is biometric support on device
fun launchBiometricFingerprintReader(
    cancellationSignal: () -> CancellationSignal,
    authenticationSucceeded: () -> Unit,
    authenticationError: () -> Unit,
    context: Context
) {
    if (hasBiometricSupport(context)) {
        val biometricPrompt = BiometricPrompt.Builder(context)
            .setTitle(FINGERPRINT_DIALOG_TITLE)
            .setSubtitle(FINGERPRINT_DIALOG_SUBTITLE)
            .setConfirmationRequired(false)
            .setNegativeButton("Back", context.mainExecutor, { _, _ ->

            })
            .build()
        biometricPrompt.authenticate(
            cancellationSignal(),
            context.mainExecutor,
            authenticationCallback(authenticationSucceeded, authenticationError)
        )
    }
}
  • In the next step i implemented fingerprint function in screens viewModel, for success and error state i simply change the value of mutableStateOf Boolean
    var hasFingerprintSecurityPassed by mutableStateOf(false)
    private set


    @RequiresApi(Build.VERSION_CODES.R)
    fun fingerprint() = viewModelScope.launch {
        launchBiometricFingerprintReader(
            { getCancelationSignal() },
            authenticationSucceeded = {
                hasFingerprintSecurityPassed = true
            },
            authenticationError = {
                hasFingerprintSecurityPassed = false
            },
            context
        )
    }
  • Last thing to do is implement this in UI. I simply did that with condition for the mutableStateOf Boolean if variable is true we show notes if false we show black screen
@RequiresApi(Build.VERSION_CODES.R)
@Composable
fun MainScreen(
    viewModel: MainScreenViewModel = hiltViewModel()
) {

    val securityPassed = viewModel.hasFingerprintSecurityPassed
    val notes = viewModel.allNotes.collectAsState(initial = emptyList()).value
    if (!securityPassed){
        viewModel.fingerprint()
        Box(modifier = Modifier.fillMaxSize().background(Color.Black))
    }else{
        FloatingAddButton(onButtonClick = { viewModel.onDialogIsOpenChange(true) }, viewModel)
        ListOfNotes(
            notes,
            viewModel,
            modifier = Modifier
                .fillMaxSize()
                .padding(16.dp)
        )
    }
}

Contacts

Ugis Ozols - [email protected]

LinkedIn - www.linkedin.com/in/uģis-ozols-2192a8226

Project Link - https://github.com/OzolsUgis/FingerprintSecurityNoteApp

About

Simple note app secured by biometric fingerprint scanner

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages