0.0.1-beta.3 • Published 4 years ago

pinlocker v0.0.1-beta.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

A simple lock screen with PIN code for hybrid mobile app

PinLocker is a simple PIN code inspired by react-native-pincode and the api is similar to that.

PinLocker are built using the Web Components standard that work on any framework or without one.

Installation

Vanilla JS

  • Put a script tag in the head of your html file then you can use the pinlocker anywhere:
<!DOCTYPE html>
<html lang="en">

<head>
   <script src="https://unpkg.com/pinlocker/latest/dist/pinlocker.js"></script>
</head>

<body>
   <pinlocker-app status="enter"></pinlocker-app>
</body>

</html>

Vue

  • Run npm install pinlocker --save

  • modify 'main.js' file as belows:

import Vue from 'vue';
import App from './App.vue';

import { defineCustomElements as definePinlocker } from 'pinlocker/dist/loader';
  
Vue.config.productionTip = false;
Vue.config.ignoredElements = ['pinlocker-app'];

definePinlocker(window)

new Vue({
render: h => h(App)
}).$mount('#app');

React

  • Run npm install pinlocker --save

  • modify index.js file as below:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

import { applyPolyfills, defineCustomElements } from 'pinlocker/dist/loader';  

ReactDOM.render(<App />, document.getElementById('root'));

registerServiceWorker();

applyPolyfills().then(() => {
   defineCustomElements(window);
});

for more information please go to https://custom-elements-everywhere.com/.

Angular

  • Run npm install pinlocker --save
  • Including the CUSTOM_ELEMENTS_SCHEMA in the module:
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
 
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})

export class AppModule {}
  • Add function defineCustomElements() to your main.ts:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { defineCustomElements } from 'pinlocker/dist/loader';
 
if  (environment.production) {
   enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));

defineCustomElements(window);

Usage

Basic usage requires choosing between the choose, enter and locked modes.

  • choose : requires the user to choose and to confirm a PIN code
  • enter : requires the user to enter the PIN code he previously chose
  • locked : prints a locked screen for a given time if the user failed to enter his/her PIN code too many times

<pinlocker-app status="enter"></pinlocker-app>

Options

AttributeDescriptionDefault
button-delete-textText of the of the button used to delete a previous entry on the PIN paneldelete
disable-lock-screenBoolean to disable the lock screenfalse
handle-result-enter-pinFunction to be used to handle the PIN code entered by the user. To be used with the pinStatus propsundefined
max-attemptsNumber of attempts the user is given before locking the application3
password-lengthLength of the password the user has to enter4
pin-statusStatus coming back to the PIN component after the handleResultEnterPin function. The status type is a value of the PinResultStatus enum (initial, success, failure, locked)undefined
statusIndicates the mode that should be used (see Usage section for the different modes available)undefined
stored-pinThe PIN code previously stored with the storePin functionundefined
subtitle-chooseString used as a subtitle on the PIN code choose pageto keep your information secure
subtitle-confirmString used as a subtitle on the PIN code confirmation pageundefined
subtitle-enterString used as a subtitle on the PIN code enter pageundefined
subtitle-errorString used as a subtitle on the PIN code pages when an error occurs (wrong PIN code used for enter or confirm modes)Please try again
text-button-locked-pageString to be used as text on the button in the locked application pageQuit
text-description-locked-pageString to be used as a description on the locked application pageTo protect your information, access has been locked for {timeLocked} minutes.
text-sub-description-locked-pageString to be used as a subtitle on the locked application pageCome back later and try again.
text-title-locked-pageString to be used as a title on the locked application pageMaximum attempts reached
time-lockedNumber of milliseconds where the application should be locked after maxAttempts failed attempts from the user300000 (5 minutes)
title-attempt-failedString used as a title on the PIN enter page when the user enters a wrong PIN codeIncorrect PIN Code
title-chooseString used as a title on the PIN choose page1 - Enter a PIN Code
title-confirmString used as a title on the PIN confirm page2 - Confirm your PIN Code
title-confirm-failedString used as a title on the PIN confirm page when the user enters a wrong PIN codeYour entries did not match
title-enterString used as a title on the PIN enter pageEnter your PIN Code

Events

EventDescriptionDefault
clickButtonLockedPageFunction to be used when the user taps the button on the locked application pageKills the app by throwing Quit application
endProcessFunctionFunction to handle the end of the processNone
finishProcessFunction to be used when the user enters the right PIN codeRemoves the values in Storage and set the status to success
getCurrentPinLengthFunction returning the length of the current PIN codeNone

Contributing

License

Changelog