šŸ›”ļø Dart Secure šŸ›”ļø

Pub Package Star on Github Forks on Github Contributors Code size License: MIT Platform

A Dart package that provides functionalities to enhance user authentication and data encryption in Dart applications. This package integrates multiple cybersecurity practices to secure sensitive user data and interactions. The package includes the following features:

Features

šŸ” Temporary Lock User

šŸ”‘ User Authentication Monitoring

āœ‹ Biometric User Authentication

šŸ”’ InApp Data Encryption

šŸ”“ InApp Data Decryption

#ļøāƒ£ Hashing Data

šŸ“– Getting Started

To use this package, add dart_secure as a dependency in your pubspec.yaml file:

dependencies:
  dart_secure: ^(check current version)

Then import the necessary features in your Dart code:

import 'package:dart_secure/dart_secure.dart';

Features

šŸ” Temporary Lock User

You can use the tempLockUser method to lock the user after multiple failed login attempts. This function takes the following parameters:

  • context (required): The BuildContext of the current screen.
  • time (optional): The duration in seconds for which the user will be locked. Default is 30 seconds.
  • afterCountNavigateTo (required): The widget to navigate to after the countdown timer finishes.
  • lockedPageMessage (optional): The message to display on the locked user page. Default is "You are temporarily locked."
Future<void> lockUser() async {
  await tempLockUser(
    context,
    time: 60, // Lock user for 60 seconds
    afterCountNavigateTo: HomeScreen(), // Navigate to HomeScreen after timer finishes
    lockedPageMessage: "Your account has been temporarily locked for security reasons.",
  );
}

Customization

You can customize the appearance of the countdown timer page by modifying the _countdownPage function. This function creates the UI displayed to the user during the lockout period.

Note

  • The package uses a StreamBuilder to display the countdown timer and navigate to the next page once the timer completes.
  • The countdown timer can't be bypassed by pressing the back button.

Example

Here's a simple example of how to use the feature:

//Temporary lock the user
void TempLockThisUser() {
  // Simulate a failed login attempt
  tempLockUser(context, afterCountNavigateTo: LoginPage());
}

šŸ”‘ User Authentication Monitoring for Firebase

The userAuthMonitor feature allows you to monitor user authentication using Firebase Auth and display different pages based on the user's authentication state. This can be particularly useful for managing user access and providing a seamless experience for authenticated and unauthenticated users.

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^<latest_version>

Usage

To get started with user authentication monitoring, you can use the userAuthMonitor function provided by the dart_secure package. This function takes various parameters to customize the behavior based on your requirements:

  • authenticatedUserPage: The page/widget to be shown when the user is authenticated.
  • unAuthenticatedUserPage: The page/widget to be shown when the user is not authenticated.
  • adminUID: The UID of the admin user (optional). If provided, a specific admin page can be shown.
  • adminPage: The page/widget to be shown if the authenticated user's UID matches the adminUID.
  • blockUID: A list of UIDs representing blocked users (optional). Blocked users will see the userBlockedPage.
  • userBlockedPage: The page/widget to be shown for blocked users.

Here's an example of how you can use this feature:

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:dart_secure/dart_secure.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: userAuthMonitor(
        authenticatedUserPage: HomePage(),
        unAuthenticatedUserPage: LoginPage(),
        adminUID: 'your_admin_uid_here',
        adminPage: AdminPage(),
        blockUID: ['blocked_user_uid_1', 'blocked_user_uid_2'],
        userBlockedPage: UserBlockedPage(),
      ),
    );
  }
}

// Define your pages/widgets here (HomePage, LoginPage, AdminPage, UserBlockedPage).

This example demonstrates how to create a seamless user authentication experience with custom pages for different user states. Make sure to replace placeholder values with your actual implementation.

This new section provides an explanation of the new feature, its installation, usage, and a sample code snippet for integrating it into your Flutter application. Make sure to adjust the placeholders and example code to fit your actual implementation and requirements.

šŸ§‘āœ‹ Biometric User Authentication

Note that this plugin works with both Touch ID and Face ID. However, to use Face ID, you need to add the following to your Info.plist file:

iOS Integration

<key>NSFaceIDUsageDescription</key>
<string>Why is my app authenticating using Face ID?</string>

Android Integration

  • The plugin will build and run on SDK 16+, but isDeviceSupported() will return false before SDK 23 (Android 6.0).

Activity Changes

local_auth requires the use of a FragmentActivity instead of an Activity. To update your application:

If you are using FlutterActivity directly, change it to FlutterFragmentActivity in your AndroidManifest.xml.

If you are using a custom activity, update your MainActivity.java or MainActivity.kt to inherit from FlutterFragmentActivity.

Permissions

Update your project's AndroidManifest.xml file to include the USE_BIOMETRIC permission:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app">
    <uses-permission android:name="android.permission.USE_BIOMETRIC"/>
</manifest>

The biometricAuth feature offers a secure way to implement biometric user authentication in your app. It supports various biometric authentication methods on the device. Example usage:

getBiometric() async {
  var authStatus = await biometricAuth();
  if (authStatus == AuthenticationStatus.successful) {
    print("Authentication successful, continue");
  } else {
    print("Authentication unsuccessful, try again");
  }
}

šŸ”’ In-App Encryption

The InAppEncryption feature allows you to encrypt sensitive data within your app using a specified encryption key:

String encryptedAddress = inAppEncrypt(text: "User's Address", key: "MyUsersAddress");

#ļøāƒ£ Hash Encryption

The hashEncryption feature securely hashes data, useful for scenarios like password storage:

String encryptedAddress = hashEncrypt(text: "User's Address");

šŸ”“ In-App Decryption

The InAppDecryption feature lets you decrypt encrypted data within your app using the appropriate decryption key:

String encryptedAddress = InAppDecryption(cipher: "######################", key: "MyUsersAddress");

Release Notes

Version 0.1.0

  • Initial release of the Dart Secure framework, providing seamless integration of various cybersecurity practices.

Version 0.2.0

  • Enhanced Biometric documentation, ensuring comprehensive coverage and clarity.

Version 0.3.0

  • Added illustrative examples for improved understanding and clarity.

Version 0.4.0

  • Added the feature of User Authentication Monitoring with examples for improved understanding and clarity.

Version 0.5.0

  • Included a new Temporary Lock User feature that can lock the user within the app for some amount of time.

For more details and information about the package usage, refer to the GitHub repository.

If you encounter issues or have improvement suggestions, open an issue on GitHub.

šŸ’™ Support DS Development šŸ’™

Buy Me A Coffee Ko-fi

šŸ‘Øā€šŸ’» Framework Developer Profile šŸ‘Øā€šŸ’»

Hi šŸ‘‹, I'm Saif Almajd

syf-almjd

Passionate of Full Stack Mobile/Web Development

saif_almajd saif_almajd saif_almajd hsaifalmajd saifalmajd

syf-almjdsyf-almjd

Favoutre Languages and Tools:

android dart figma firebase flutter

  • šŸ”­ Iā€™m currently working on a Dart Secure Security Framework

  • šŸŒ± Iā€™m currently learning Flutter, SQL, Firebase, Dart

  • šŸ‘Øā€šŸ’» All of my projects are available at SaifAlmajd.web.app/

  • šŸ’¬ Ask me about Flutter, Java, Data Structure & Algorithms

  • šŸ“« How to reach me syfalmjd11@gmail.com

  • āš” Fun fact I am an AspireX Leadership Alumni :)

syf-almjd

Languages and Tools:

android dart figma firebase flutter gcp git java laravel linux mysql

syf-almjd

I proudly embrace my roles as a Developer, Leader, and Believer in our shared journey toward a better humanity šŸŒŽ.

šŸ‘ØšŸ»ā€šŸ’» As a committed computer science professional and visionary leader, my mission is to harness the potential of technology to uplift humanity and leave a positive imprint on our world. In my capacity as the Manager of MJD Foundation, my focus is unwavering ā€“ I endeavor to craft ingenious tools that enhance and simplify the lives of everyone.

šŸ”§ Expertise

  • šŸ’¼ Mobile Development: Passionately expanding my expertise in mobile development to create user-friendly and innovative solutions.

  • šŸ”’ Cybersecurity: Committed to ensuring the safety and security of digital landscapes in an increasingly connected world.

  • šŸš€ Project Management and Leadership: Proficiently orchestrating projects from inception to completion, optimizing resources, and leading cross-functional teams to deliver successful outcomes.

šŸŒ± Continuous Learning

My unwavering belief in the power of continuous learning drives me to stay at the forefront of the latest advancements in the field.

šŸ’Ŗ Versatility

With a background as a seasoned software engineer, I possess the versatility to navigate diverse platforms and excel in both written and verbal communication. My precision-oriented approach enables me to demystify intricate software challenges into easily digestible concepts.

šŸ¤ Collaboration

I am actively seeking collaborative opportunities in the domains of Flutter, Dart, Cybersecurity, and Mobile Development. If you share my enthusiasm for creating groundbreaking solutions, please don't hesitate to reach out to me at syfalmjd11@gmail.com.

Let's join forces and shape technology into a more human-centric and empowering force for our global community! šŸŒŽ

Connect with Me:

https://dev.to/saifalmajd hsaifalmajd saif-almajd 19370215 saif_almajd/ saifalmajd @saifalmajd syfalm4h6f https://github.com/syf-almjd.atom

Support:

https://www.buymeacoffee.com/saifalmajdalmassri   https://ko-fi.com/saifalmajdalmassri



Libraries

dart_secure