Skip to content

An npm package for advanced sign-in security, including AI-based risk assessment, anomaly detection, real-time PostgreSQL database, automated user management and MFA. Compatible with React, Vue, and Angular

License

Notifications You must be signed in to change notification settings

Jai0212/secure-auth-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SecureAuthAI

npm version npm Frameworks

🔐 SecureAuthAI offers web developers a comprehensive solution for implementing secure sign-in functionalities.

This npm package integrates multi-factor authentication (MFA), real-time PostgreSQL database management, statistical anomaly detection, and a custom AI model. Designed to enhance login security, it automates user management tasks and ensures robust protection against unauthorized access.

It integrates seamlessly with popular web frameworks like React, Vue, and Angular.

Features

  • AI-Based Risk Assessment: Custom AI model detects unsafe login attempts based on location, device, time, and attempts.
  • Anomaly Detection: Statistical methods (Z-Score Calculation) to identify anomalies and prevent unauthorized access.
  • MFA Integration: Enhances security with multi-factor authentication using a secret key.
  • Realtime PostgreSQL Database: Store user details securely with customizable functions provided out-of-the-box.
  • Hassle-Free Implementation: Pre-made functions handle database interactions, eliminating the need for manual API calls.
  • Security: Passwords are tokenized, and user-specific details are automatically managed to prevent security breaches.

Framework Support

SecureAuthAI integrates seamlessly with popular web frameworks:

React Vue.js Angular

Installation & Usage:

Install SecureAuthAI via npm:

npm install secure-auth-ai

Import the package in your project:

import * as SAA from 'secure-auth-ai';

Or import specific functions:

import { initializePackageSAA, signUpSAA } from 'secure-auth-ai';

All functions are asynchronous and should be used with axios for HTTP requests:

const response = await initializePackageSAA();

Each response has three attributes to it:

  • value - any value that needs to be returned. If not, or in case of an error, this will be either an empty string or []
  • success - true if request was successful, false otherwise
  • message - message for debugging in case of an error or a success message

When you first use the package, you must call the function initializePackageSAA() which will give you a token that refers to your table. This token is the first parameter in all other functions.

Example

import { initializePackageSAA, signUpSAA, updateUserDetailsSAA, getUserDetailsSAA } from 'secure-auth-ai';
 
const SECURE_AUTH_AI_TABLE_KEY = await initializePackageSAA(["email"]);

const signUpResponse = await signUpSAA(SECURE_AUTH_AI_TABLE_KEY, "hello", {"email": "placeholder@example.com", "phone_number": "+123456789"});

if (signUpResponse.success) {
    const updateResponse = await updateUserDetailsSAA(SECURE_AUTH_AI_TABLE_KEY, "email", "placeholder@example.com", {"phone_number": "+199999999"});

    console.log(updateResponse.message);

    const detailsResponse = await getUserDetailsSAA(SECURE_AUTH_AI_TABLE_KEY, "email", "placeholder@example.com");

    console.log(detailsResponse.value);
}

Everytime the function logInSAA() is called, using the AI model and anomaly detection, it is checked whether the login attempt is safe or not. If it is not safe, you are required to call verifyMfaSSA() to do the MFA.

NOTE: Initally it can take about a minute to get a response as the backend needs to load up.

Available Functions

  • initializePackageSAA
  • signUpSAA
  • logInSAA
  • verifyMfaSAA
  • getUserDetailsSAA
  • getAllDetailsSAA
  • updateUserDetailsSAA
  • addColumnSAA
  • removeColumnSAA
  • removeUserSAA

NOTE: All functions are ASYNCHRONOUS

For detailed usage of each function, refer to the api.js file.

Technical Aspects

  • Backend: Python backend hosted on Render
  • Database: PostgreSQL hosted on Neon
  • Package: JavaScript and Node.js, published on npm
  • AI Model:
    • Created using:
      • XGBoost Classifier
      • Random Forest Classifier
    • Training Data based on change in:
      • Location
      • Device
      • Time
      • Attempts
  • Anomaly Detection: Z-Score Calculation for detecting unusual login patterns.
  • Prediction: Based on the variation in location, device, time & attempts, along with the anomaly detection, it is decided whether a particular login attempt is safe or not

Files

  • backend/ - Core logic and AI model implementation.
  • api.js - API calls.

Webpack Configuration

If you're using React (Webpack) and encounter issues with missing core Node.js modules (like crypto), you may need to update your Webpack configuration. Add the following to your webpack.config.js (found inside node_modules/react-scripts/config/):

resolve: {
  fallback: {
    crypto: false,
    // Add other fallbacks if necessary
  }
}

Acknowledgments

Special thanks to Render, Neon, and npm for their support in hosting and distributing this package.

Contact

For suggestions, feedback, collaborations, or bug reports, please contact me via email: jj.joshijai@gmail.com

Author and Date
by Jai Joshi
Updated on 19th July, 2024

About

An npm package for advanced sign-in security, including AI-based risk assessment, anomaly detection, real-time PostgreSQL database, automated user management and MFA. Compatible with React, Vue, and Angular

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published