π 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.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Include below dependency in build.gradle of application and sync it:
implementation 'com.github.raheemadamboev:pin-lock-compose:1.0.1'
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()
You can install and try demo app. All the features are implemented in the demo from creating pin to changing pin.
Notepad: 40 000+ downloads.
Designed and developed by raheemadamboev (Raheem) 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.