Skip to content

zaneschepke/pin_lock_compose

 
 

Repository files navigation

Pin Lock

Android License API

🔐 Light library that is beautiful Pin Lock screen for Jetpack Compose. The library handles saving pin in Encrypted file. Integration is very easy and fast.

Download

repositories {

// recommended repo
  mavenCentral()

// alternative repos
  maven("https://gitea.zaneschepke.com/api/packages/zane/maven")
  maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/zaneschepke/pin-lock-compose")
            credentials {
                username = GITHUB_USERNAME
                password = GITHUB_TOKEN
            }
        }
}

dependencies {
  implementation("com.zaneschepke:pin_lock_compose:1.0.3")
}

Implementation

Firstly, initialize the library on your onCreate of Application class:

PinManager.initialize(this)

To add Pin Lock screen, add the PinLock composable to your compose area:

PinLock(
  title = { pinExists ->
    Text(text = if (pinExists) "Enter your pin" else "Create pin")
  },
  color = MaterialTheme.colorScheme.primary,
  onPinCorrect = {
    // pin is correct, navigate or hide pin lock
  },
  onPinIncorrect = {
     // pin is incorrect, show error
  },
  onPinCreated = {
     // pin created for the first time, navigate or hide pin lock
  }
)

If there is no saved pin yet, it promtps the user to create pin. If there is saved pin, it promts the user to enter its pin:


It is also possible to change pin. Just add ChangePinLock composable to your compose area:

ChangePinLock(
  title = { authenticated ->
    Text(text = if (authenticated) "Enter new pin" else "Enter your pin")
  },
  color = MaterialTheme.colorScheme.primary,
  onPinIncorrect = {
    // pin is incorrect, show error
  },
  onPinChanged = {
    // pin changed, navigate or hide pin lock
  }
)

Use this only if there is already saved pin. If there is no saved pin, use simple PinLock instead for creating pin for the first time. When using ChangePinLock, firstly it prompts the user to enter original pin. After user succesfully authenticates using his original pin, it prompts the user to creat a new pin:


To check if saved pin exists:

val pinExists = PinManager.pinExists()

To clear saved pin so user can create brand new pin:

PinManager.clearPin()

Features

  • pin lock screen very easily
  • handles encryption and saving pin internally
  • change pin lock screen
  • customizable background color
  • robust to configuration changes
  • backspace to remove last entered pin number
  • incorrect indicator animation

Demo

You can install and try demo app. All the features are implemented in the demo from creating pin to changing pin.

Download demo