Giter Club home page Giter Club logo

biometrics-authentication's Introduction

Swift: Biometric authentication

- a study -

Β‘Hola mundo!

In the project I work we have biometric authentication and this has been a huge mistery for me. But the time has come! I decided I wanted to learn a little bit more about it. How does it work and how it is managed.

This is a super simple study repo to put on practice biometrics authentication in Swift.

Features πŸ“‹

  • A login button that must call biometrics
  • If the authentication is successful the user must enter the app, and maybe find The Secret of Monkey Island β„’
  • If the authentication fails we must ask the user their device PIN

Built with πŸ”¨

  • XCode
  • Swift
  • SwiftUI

Development ⌨️

Views πŸ‘€β€Š

There are two simple views, one with a button to login. This button is the one that will request the biometrics. The LoginView will only be rendered if the user is not already logged in. This is managed with a Published variable in our AppState called loggedIn.

When this variable value changes to true we show the ContentView that is - or not - The Secret of Monkey Island β„’. In the real life this would be a real app.

Biometrics and AppState πŸ“±

Apple documentation is very good regarding this. I've created an AppState file where I manage my authentication methods and variables. There are three different methods here:

  • checkBiometricsAvailability() this method checks if the user has biometrics active. If the BiometryType is different than none, that means that it has finger or face ID activated. So it will return a true value. If not it will be false. I've decided not to manage the false value because for the end of this repo is not useful.

  • requestBiometrics()is the main one. Here we first call the checkBiometricsAvailability() if this returns a true then it will show the Finger or FaceId native interface. If the authentication is successful the loggedIn variable is set to true and as is Published the view will reload to show the app. If the authentication fails, I'm managing the errors inside a switch where in the case that the authentication fails or the user cancels the authentication prompt then we call the third and last method requestPinAuthentication()

  • requestPinAuthentication() this method shows a prompt and ask the user to enter their device PIN in order to authenticate their identity.

Check out the app in motion πŸ‘€πŸŽ¬

Biometrics success

RPReplay_Final1683876188.mov

Biometrics fails, pin is requested

RPReplay_Final1683876188.1.mov

Want to fork this repo? πŸ‘

Please feel free and let me know what amazing things you have done.

biometrics-authentication's People

Contributors

silviaespanagil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.