• Stars
    star
    272
  • Rank 151,235 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PasscodeView is an Android Library to easily and securely authenticate user with PIN code or using the fingerprint scanner.

PasscodeView

Build Status Download API Javadoc

PasscodeView is an Android Library to easily and securely authenticate the user with the PIN code or using the fingerprint scanner.

Whyโ“

  • Secure authentication is the key factor in many application (e.g. financial applications). Many application uses PIN-based authentication.

  • But Android System doesn't provide any easy to set the view for PIN-based authentication which can tightly integrate and take advantage of fingerprint API introduced in newer versions of android. This limitation led me to work on this project.

  • With the use of PasscodeView, you can easily integrate PIN & Fingerprint based authentication in your application.

Features:

This library provides an easy and secure PIN and Pattern based authentication view, which

  • It provides access to built-in fingerprint-based authentication if the device supports fingerprint hardware. This handles all the complexities of integrating the fingerprint API with your application.
  • It provides error feedback when PIN or pattern entered is wrong.
  • Extremely lightweight.
  • Supports dynamic PIN sizes for PIN-based authentication. That means you don't have to provide a number of PIN digits at runtime.
  • Supports custom authentication logic for PIN and Pattern. That means you can send the PIN or pattern to the server for authentication too.
  • It is highly customizable. So that you can match it with your application them. It provides you control over,
    • color and shape of each key. ๐Ÿ‘‰ Guide
    • localized name of each key in pin keyboard. ๐Ÿ‘‰ Guide
    • size of every single key.
    • color and shape of indicators to display a number of digits in the PIN.๐Ÿ‘‰ Guide
    • color and shape of pattern indicators.
    • tactile feedback for key press and authentication success/failure events.

Demo:

Authentication using PIN/Fingerprint

Success Fail
PIN Success PIN Failed
Fingerprint Success Fingerprint Fail
Fingerprint Success Fingerprint Failed

Pattern based authentication

Pattern Unlock

Here is the link of the demo application. ๐Ÿ‘‰ Demo

How to use this library?

  • Gradle Dependency:

    • Add below lines to app/build.gradle file of your project.
    dependencies {
        compile 'com.kevalpatel2106:passcodeview:2.0.0'
    }
    
    • To integrate using maven visit this page.

PIN based authentication:

  • Add PinView in your layout file.

    <com.kevalpatel.passcodeview.PinView
            android:id="@+id/pin_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/imageView"
            app:dividerColor="@color/colorPrimaryDark"
            app:fingerprintDefaultText="Scan your finger to unlock application"
            app:fingerprintEnable="true"
            app:fingerprintTextColor="@color/colorAccent"
            app:fingerprintTextSize="@dimen/finger_print_text_size"
            app:titleTextColor="@android:color/white"/>
  • Get the instance of the view in your activity/fragment.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //....          
      PinView pinView = (PinView) findViewById(R.id.pin_view);
      //...
    }
  • Set the authenticator which will tell if your pin is correct or not.

    • The library provides inbuilt PasscodeViewPinAuthenticator. This authenticator will match the pin entered by the user with the correct PIN provided.
    • You can write your custom authenticator to customize the authentication logic.
       //Set the authenticator.
       //REQUIRED
       final int[] correctPin = new int[]{1, 2, 3,4}; 
       pinView.setPinAuthenticator(new PasscodeViewPinAuthenticator(correctPin));
  • Set the PIN length.

    • If you know the number of digits in the PIN you can set it.
    • But if you don't know the size of the PIN in advance you can set it to PinView.DYNAMIC_PIN_LENGTH. By default, if you don't set the size PinView will consider it dynamic PIN length.
      pinView.setPinLength(PinView.DYNAMIC_PIN_LENGTH);
  • Set the shape of the key you want to use.

    • There are three built-in key shapes. You can also generate your own key by extending Key class.
      • Round key
      • Rectangle key
      • Square key
    • You can create your custom key using this guide. ๐Ÿ‘‰ Custom key wiki
    • Here is the example for the round keys.
     //Build the desired key shape and pass the theme parameters.
     //REQUIRED
     pinView.setKey(new RoundKey.Builder(pinView)
             .setKeyPadding(R.dimen.key_padding)
             .setKeyStrokeColorResource(R.color.colorAccent)
             .setKeyStrokeWidth(R.dimen.key_stroke_width)
             .setKeyTextColorResource(R.color.colorAccent)
             .setKeyTextSize(R.dimen.key_text_size));

    Different Key Shape

    Rectangle Circle Square
    Rect Circle Square
  • Set the shape of the pin indicators you want to use.

    • There are three built in key shapes.
      • Round indicator
      • Dot indicator
      • Circle indicator
    • If you want to create custom indicator with the custom shape, see How to create custom indicator?.
    • Here is the example for the round indicator.
        //Build the desired indicator shape and pass the theme attributes.
        //REQUIRED
        pinView.setIndicator(new CircleIndicator.Builder(pinView)
                .setIndicatorRadius(R.dimen.indicator_radius)
                .setIndicatorFilledColorResource(R.color.colorAccent)
                .setIndicatorStrokeColorResource(R.color.colorAccent)
                .setIndicatorStrokeWidth(R.dimen.indicator_stroke_width));
  • Set key names.

    • Set the texts to display on different keys. This is an optional step. If you don't set the key names, by default PINView will display English locale digits.
    • If you want to learn more about key name localization visit here.
        //Set the name of the keys based on your locale.
        //OPTIONAL. If not passed key names will be displayed based on english locale.
        pinView.setKeyNames(new KeyNamesBuilder()
              .setKeyOne(this, R.string.key_1)
              .setKeyTwo(this, R.string.key_2)
              .setKeyThree(this, R.string.key_3)
              .setKeyFour(this, R.string.key_4)
              .setKeyFive(this, R.string.key_5)
              .setKeySix(this, R.string.key_6)
              .setKeySeven(this, R.string.key_7)
              .setKeyEight(this, R.string.key_8)
              .setKeyNine(this, R.string.key_9)
              .setKeyZero(this, R.string.key_0));

    Localized Texts

    English Hindi
    Locale English Locale Hindi
  • Set callback listener to get callbacks when the user is authenticated or authentication fails.

        pinView.setAuthenticationListener(new AuthenticationListener() {
            @Override
            public void onAuthenticationSuccessful() {
                //User authenticated successfully.
                //Navigate to next screens.
            }
    
            @Override
            public void onAuthenticationFailed() {
                //Calls whenever authentication is failed or user is unauthorized.
                //Do something if you want to handle unauthorized user.
            }  
        });

Pattern based authentication:

  • Add PatternView in your layout file.

    <com.kevalpatel.passcodeview.PatternView
            android:id="@+id/pattern_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/imageView"
            app:dividerColor="@color/colorPrimaryDark"
            app:fingerprintDefaultText="Scan your finger to unlock application"
            app:fingerprintEnable="true"
            app:fingerprintTextColor="@color/colorAccent"
            app:fingerprintTextSize="@dimen/finger_print_text_size"
            app:giveTactileFeedback="true"
            app:patternLineColor="@color/colorAccent"
            app:titleTextColor="@android:color/white"/>
  • Get the instance of the view in your activity/fragment.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      PatternView patternView = (PatternView) findViewById(R.id.pattern_view);
      //...
    }
  • Set the number of rows and columns of the pattern in your activity/fragment.

      //Set number of pattern counts.
      //REQUIRED
      patternView.setNoOfColumn(3);   //Number of columns
      patternView.setNoOfRows(3);     //Number of rows
  • Set the authenticator

    • Set the authenticator which will tell if your pattern is correct or not.
    • The library provides inbuilt PasscodeViewPatternAuthenticator . This authenticator will match the pattern entered by the user with the correct pattern provided.
    • You can write your custom authenticator to customize the authentication logic.
    • Here is the example with the inbuilt pattern authenticator. Make sure your PatternPiont row or column number is not greater than the number of row and number of columns from the previous step.
       //Set the correct pin code.
       //Display row and column number of the pattern point sequence.
       //REQUIRED
       final PatternPoint[] correctPattern = new PatternPoint[]{
               new PatternPoint(0, 0),
               new PatternPoint(1, 0),
               new PatternPoint(2, 0),
               new PatternPoint(2, 1)
       };
       patternView.setAuthenticator(new PasscodeViewPatternAuthenticator(correctPattern));
  • Set the pattern cell shape.

    • There are two built-in pattern cells available.
      • Circle indicator
      • Dot indicator
    • If you want to create custom pattern cell with the custom shape, see How to create custom indicator?.
    • Here is the example of the round indicator.
      //Build the desired indicator shape and pass the theme attributes.
      //REQUIRED
      patternView.setPatternCell(new CirclePatternCell.Builder(patternView)
              .setRadius(R.dimen.pattern_cell_radius)
              .setCellColorResource(R.color.colorAccent));
  • Set callback listener to get callbacks when the user is authenticated or authentication fails.

    patternView.setAuthenticationListener(new AuthenticationListener() {
        @Override
        public void onAuthenticationSuccessful() {
            //User authenticated successfully.
        }

        @Override
        public void onAuthenticationFailed() {
            //Calls whenever authentication is failed or user is unauthorized.
            //Do something
        }
    });

Visit our wiki page for more information.

How to contribute?

Questions?๐Ÿค”

Hit me on twitter Twitter

License

Copyright 2017 Keval Patel

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.

More Repositories

1

android-hidden-camera

This library is to take picture using camera without camera preview.
Java
396
star
2

android-ruler-picker

Android custom view that uses ruler for picking the number from given range.
Java
381
star
3

EmoticonGIFKeyboard

An advance Emoticons & GIF keyboard.
Java
273
star
4

android-samples

Repository that contains android tutorial projects and sample applications
Java
229
star
5

Prevent-Screen-Off

This is the library that keeps the screen on until user is looking at the screen.
Java
176
star
6

FingerprintDialogCompat

FingerprintDialog from Android 28 (P) back ported to Android 23 (M).
Java
104
star
7

android-ringtone-picker

Simple Ringtone Picker dialog which allows you to pick different sounds from ringtone, alarm tone, notification tone and music from external storage.
Java
74
star
8

green-build

An android app for managing your CI builds.
Kotlin
73
star
9

UserAwareVideoView

A customized video view that will automatically pause video is user is not looking at device screen!!!!!
Java
51
star
10

Open-Weather-API-Wrapper

An Android wrapper for the APIs of https://openweathermap.org
Java
22
star
11

remote-storage-android-things

Create an FTP server using on raspberry pi and build your own wireless storage & backup solution for home.
Java
20
star
12

year-in-progress

Deadline tracker
Kotlin
17
star
13

PastryShop

Take home task for the cookpad interview (Sr. Android Engineer) 2018
Kotlin
15
star
14

smart-lens

Get the information of object based on image recognition using TensorFlow.
Java
12
star
15

unity-lamborghini-car

See Lamborghini in the real world.
C#
12
star
16

unity-snake-game

This is smaple 2D unity snake game.
C#
12
star
17

collision-detector-android-things

Get the distance of the object using Android Things & ultrasonic ranging sensor HC-SR04.
Java
10
star
18

pocket-ci

Check your builds from your pocket
Kotlin
9
star
19

smartswitch

Control your home switches remotely from phone using Android Things.
Java
9
star
20

torrent-downloader-android-things

Java
7
star
21

github-issue-cloud-function

๐Ÿ”ฅ Firebase cloud function to post a GitHub issue whenever new crash๐Ÿž reported in firebase crashalytics.
JavaScript
7
star
22

rxbus

Implementation of event bus using Rx for Android.
Java
5
star
23

remote-bluetooth-speaker-android-things

Java
5
star
24

Currency-Converter-App

Currency converter android app
Kotlin
4
star
25

robo-car

Java
4
star
26

crypto-wallet

Demo application for displaying the Bitcoin transaction in Crypto Wallet.
Kotlin
3
star
27

gitlab-ci-android

GitLab CI Docker image to create android builds.
Shell
3
star
28

basic-android

A ready to start from scratch setup for android application project
Java
3
star
29

Github-User-Search

Java
3
star
30

vuforia-barcode-scanner

A barcode scanner for Vuforia based AR applications.
C#
2
star
31

google-home-andorid-things

Protocol Buffer
2
star
32

Stand-Up

Sitting is next cancer.
Kotlin
2
star
33

brew

Kotlin
2
star
34

kevalpatel2106.github.io

Source code for my personal website.
SCSS
2
star
35

rpi-setup

This script will set up your raspberry pi after first boot.
Shell
1
star
36

kevalpatel2106

1
star
37

ar-solar-system

Augmented reality specific model of the solar system using unity in ARCore.
C#
1
star
38

SpinWheelView

Java
1
star
39

home

Java
1
star