diff --git a/biometrics/.gitignore b/biometrics/.gitignore new file mode 100644 index 00000000..0fa6b675 --- /dev/null +++ b/biometrics/.gitignore @@ -0,0 +1,46 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/biometrics/.metadata b/biometrics/.metadata new file mode 100644 index 00000000..3c3e4b52 --- /dev/null +++ b/biometrics/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 5464c5bac742001448fe4fc0597be939379f88ea + channel: stable + +project_type: app diff --git a/biometrics/LICENSE b/biometrics/LICENSE new file mode 100644 index 00000000..cafdb1ba --- /dev/null +++ b/biometrics/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Sushan Shakya + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/biometrics/README.md b/biometrics/README.md new file mode 100644 index 00000000..2d1ef28f --- /dev/null +++ b/biometrics/README.md @@ -0,0 +1,16 @@ +# biometrics + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) + +For help getting started with Flutter, view our +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/biometrics/analysis_options.yaml b/biometrics/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/biometrics/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/biometrics/android/.gitignore b/biometrics/android/.gitignore new file mode 100644 index 00000000..6f568019 --- /dev/null +++ b/biometrics/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/biometrics/android/app/build.gradle b/biometrics/android/app/build.gradle new file mode 100644 index 00000000..4e013d31 --- /dev/null +++ b/biometrics/android/app/build.gradle @@ -0,0 +1,68 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion flutter.compileSdkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "studio.sdev.biometrics" + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/biometrics/android/app/src/debug/AndroidManifest.xml b/biometrics/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..02d07602 --- /dev/null +++ b/biometrics/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/biometrics/android/app/src/main/AndroidManifest.xml b/biometrics/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..9df128ef --- /dev/null +++ b/biometrics/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/biometrics/android/app/src/main/kotlin/studio/sdev/biometrics/MainActivity.kt b/biometrics/android/app/src/main/kotlin/studio/sdev/biometrics/MainActivity.kt new file mode 100644 index 00000000..c1719e07 --- /dev/null +++ b/biometrics/android/app/src/main/kotlin/studio/sdev/biometrics/MainActivity.kt @@ -0,0 +1,5 @@ +package studio.sdev.biometrics + +import io.flutter.embedding.android.FlutterFragmentActivity +class MainActivity: FlutterFragmentActivity() { +} diff --git a/biometrics/android/app/src/main/res/drawable-v21/launch_background.xml b/biometrics/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/biometrics/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/biometrics/android/app/src/main/res/drawable/launch_background.xml b/biometrics/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 00000000..304732f8 --- /dev/null +++ b/biometrics/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/biometrics/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/biometrics/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..db77bb4b Binary files /dev/null and b/biometrics/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/biometrics/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/biometrics/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..17987b79 Binary files /dev/null and b/biometrics/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/biometrics/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/biometrics/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..09d43914 Binary files /dev/null and b/biometrics/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/biometrics/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/biometrics/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..d5f1c8d3 Binary files /dev/null and b/biometrics/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/biometrics/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/biometrics/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..4d6372ee Binary files /dev/null and b/biometrics/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/biometrics/android/app/src/main/res/values-night/styles.xml b/biometrics/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 00000000..3db14bb5 --- /dev/null +++ b/biometrics/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/biometrics/android/app/src/main/res/values/styles.xml b/biometrics/android/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..d460d1e9 --- /dev/null +++ b/biometrics/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/biometrics/android/app/src/profile/AndroidManifest.xml b/biometrics/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 00000000..02d07602 --- /dev/null +++ b/biometrics/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/biometrics/android/build.gradle b/biometrics/android/build.gradle new file mode 100644 index 00000000..4256f917 --- /dev/null +++ b/biometrics/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.6.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/biometrics/android/gradle.properties b/biometrics/android/gradle.properties new file mode 100644 index 00000000..94adc3a3 --- /dev/null +++ b/biometrics/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/biometrics/android/gradle/wrapper/gradle-wrapper.properties b/biometrics/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..bc6a58af --- /dev/null +++ b/biometrics/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 23 08:50:38 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/biometrics/android/settings.gradle b/biometrics/android/settings.gradle new file mode 100644 index 00000000..44e62bcf --- /dev/null +++ b/biometrics/android/settings.gradle @@ -0,0 +1,11 @@ +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/biometrics/lib/biometrics_verifier.dart b/biometrics/lib/biometrics_verifier.dart new file mode 100644 index 00000000..256e9bc5 --- /dev/null +++ b/biometrics/lib/biometrics_verifier.dart @@ -0,0 +1,34 @@ +import 'package:flutter/services.dart'; +import 'package:local_auth/local_auth.dart'; + +class BiometricsVerifier { + late LocalAuthentication auth; + + BiometricsVerifier() { + auth = LocalAuthentication(); + } + + Future _ableToAuthenticate() async { + bool supported = await auth.canCheckBiometrics; + bool entryExists = await auth.isDeviceSupported(); + if (!supported) throw "Device doesn't support Biometrics."; + if (!entryExists) throw "Biometric entry not found in phone."; + } + + Future verifyBiometrics(String? prompt) async { + await _ableToAuthenticate(); + late bool didAuthenticate; + try { + didAuthenticate = await auth.authenticate( + localizedReason: prompt ?? 'Please authenticate with biometrics', + options: const AuthenticationOptions( + stickyAuth: true, + biometricOnly: true, + ), + ); + } on PlatformException { + throw "Platform Exception : Biometrics Failed !"; + } + if (!didAuthenticate) throw "Biometrics Failed"; + } +} diff --git a/biometrics/lib/main.dart b/biometrics/lib/main.dart new file mode 100644 index 00000000..3e32195f --- /dev/null +++ b/biometrics/lib/main.dart @@ -0,0 +1,99 @@ +import 'package:biometrics/biometrics_verifier.dart'; +import 'package:flutter/material.dart'; + +void main() => runApp(Biometrics()); + +class Biometrics extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Biometrics', + theme: ThemeData( + appBarTheme: const AppBarTheme(elevation: 0), + ), + home: Home(), + ); + } +} + +class Home extends StatefulWidget { + @override + State createState() => _HomeState(); +} + +class _HomeState extends State { + late bool isVerified; + + late BiometricsVerifier verifier; + + @override + void initState() { + super.initState(); + isVerified = false; + verifier = BiometricsVerifier(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: SizedBox( + width: double.infinity, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + isVerified ? 'Verification Complete' : 'Unverified', + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), + isVerified + ? TextButton( + onPressed: () { + setState(() { + isVerified = false; + }); + }, + child: const Text('Unverify'), + ) + : TextButton( + onPressed: () async { + try { + await verifier + .verifyBiometrics('Please enter your fingerprint'); + // ---- Add your logic after finger print verification here + // --- + // --- + setState(() { + isVerified = true; + }); + } catch (e) { + // ---- Verification Failed + showDialog( + context: context, + builder: (c) => AlertDialog( + title: const Text('Error !'), + content: Text(e.toString()), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Ok'), + ) + ], + ), + ); + } + }, + child: const Text('Verify with Fingerprint'), + ), + ], + ), + ), + ); + } +} diff --git a/biometrics/pubspec.yaml b/biometrics/pubspec.yaml new file mode 100644 index 00000000..c767ab49 --- /dev/null +++ b/biometrics/pubspec.yaml @@ -0,0 +1,90 @@ +name: biometrics +description: A new Flutter project. + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +version: 1.0.0+1 + +environment: + sdk: ">=2.16.2 <3.0.0" + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + local_auth: ^2.1.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^1.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware. + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages