Library for user authentication using PIN code. This library provides convenient and secure ways to verify users' identities using a simple numeric PIN. It can be used by developers when creating applications that require an additional layer of security or user authentication.
- Simple and intuitive PIN authentication.
- Reliable storage and protection of user PIN codes using encryption.
- Ability to customize the required length and complexity of the PIN code.
- Limit the number of attempts to enter a PIN code to prevent brute force attacks.
- Advanced configuration options and event notifications.
This tutorial will help you become familiar with using the PIN authentication library in your application. The library provides a simple and reliable way to protect access to your application using a PIN code. Let's figure out how it works:
Installing a PIN authentication library is the first step to securely protecting your application.
- Add the dependency to your build.gradle file:
dependencies {
implementation 'com.github.Khokhlinvladimir:android-pin-authentication:v1.0.5'
}
With this simple step, you will enable a powerful authentication tool in your application, making it reliable and secure.
- Specifying the repository in the settings.gradle file:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Don't forget to add this setting to your settings.gradle file to ensure the library will be available for download.
In your activity or fragment, initialize the library like this:
val pinCodeStateManager = PinCodeStateManager.getInstance()
Set security options such as maximum number of PIN attempts, PIN length, and biometric authentication activation:
pinCodeStateManager.setMaxPinAttempts(maxAttempts = 4, application = application)
pinCodeStateManager.setPinLength(pinLength = 4, application = application)
pinCodeStateManager.setBiometricEnabled(enabled = true, application = application)
pinCodeStateManager.autoLaunchBiometricEnabled(enabled = true,application = application)
The library supports four main scenarios:
pinCodeStateManager.setScenario(PinCodeScenario.CREATION)
Allows the user to create a new PIN.
pinCodeStateManager.setScenario(PinCodeScenario.VALIDATION)
The user can log into the application by entering their existing PIN. The library will check the entered PIN code for compliance and, if validated successfully, will provide access to the application.
pinCodeStateManager.setScenario(PinCodeScenario.CHANGE)
Allows the user to change their current PIN to a new one.
pinCodeStateManager.setScenario(PinCodeScenario.DELETION)
The user can delete their current PIN.
Handle events such as successful PIN creation, validation, change, and deletion, as well as input attempts exhaustion:
pinCodeStateManager.onCreationSuccess {
// Handle successful PIN setting
}
pinCodeStateManager.onValidationSuccess {
// Handle successful PIN validation
}
pinCodeStateManager.onLoginAttemptsExpended {
// Handle exhaustion of PIN entry attempts
}
// and so on for other events
Integrate the library with your application's interface
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
// Display a screen for entering or validating a PIN code
PinCodeScreen()
}
These are the basic steps to use the library for PIN authentication in your Android application. Customize the library and handle events according to your needs to create a secure and seamless user experience.
Minimum SDK version (minSdk): 24
Target SDK version (targetSdk): 34
Gradle version: 8.5.2
OpenJDK Version: 17.0.1
This library is distributed under the MIT license. Details can be found in the LICENSE file.
The library is developed and maintained by Khokhlin Vladimir. You can contact me via telegram @vkhokhlin.
If you have suggestions for improving the library or find a bug, please create an issue or send a pull request to the GitHub repository.