1.0.1 β€’ Published 9 months ago

nvbm v1.0.1

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
9 months ago

nvbm - number verification & Ban Management βš”οΈ

npm version license downloads Logo

Table of Contents πŸ“•

Introduction πŸ’‘

nvbm is a powerful and flexible Node.js package for verifying numbers with codes, managing repeated requests, and banning users based on their device ID. Whether you're building a web or mobile application, nvbm helps you secure your app with authentication mechanisms and rate-limiting strategies.

Features πŸš€

  • βœ… Verify user phone numbers with custom codes
  • 🚫 Ban users based on device ID
  • πŸ“¦ Integration with Sequelize and MySQL
  • βœ” Simple API with async/await support

Installation πŸ“₯

You can install the package via npm:

npm install nvbm --save

API ⭐

createDB

  • args: dbName, username, password, hostname
  • First, create a database and then send its values ​​mentioned above to nvbm.createDB()

    useSequelize

  • args: sequelize

  • If you use Sequelize, it is better to use this method and give it only one instance of Sequelize as input.

    checkBanDevice

  • args: device_id

  • Before you want to send a confirmation code, check whether the user with a certain device_id is prohibited from receiving SMS or not.

    addRequest

  • args: number, code, device_id, checkBanDevice

  • If the user with her specific device_id was not restricted, we can confirm the request to receive the code and after receiving the code, we will call the addRequest() method (pay attention that you must also give the response checkBanDevice() to its input)

    codeExist

  • args: number, code, device_id

  • In the last step, when the user wants to send the received code for authentication, we call this method

Example πŸ“Œ

Pay attention to explanations:

  • banTimeList: Each time it is requested by a device_id, according to the value provided each time, it takes n time for the user to unblock (if it reaches the end of the list, it starts from the beginning) -> ( custom )
  • verifyTimer: Once the code is submitted, you have n seconds to submit the code for verification -> ( custom )
  • exampleCode: The amount of the code you received from anywhere (for example, SMS panel)
  • exampleDeviceID: You should get a unique ID from the client
import NVBM from 'nvbm'

const banTimeList = [60, 120, 180, 500, 3600] // array sec: 
const verifyTimer = 120 // sec ( 2 min )

const nvbm = new NVBM(banTimeList, verifyTimer)
await nvbm.useSequelize(sequelize) // or: await nvbm.createDB('dbName', 'root', '', 'localhost')
// first check ban list
const checkBanDeviceRes = await nvbm.checkBanDevice("exampleDeviceID") // you can log 'checkBanDeviceRes' ( maybe user is ban ( device_id ) )
if(!checkBanDeviceRes.isBan) {
  // call for send code to your number
  console.log(await nvbm.addRequest("exampleNumber", "exampleCode", "exampleDeviceID", checkBanDeviceRes)) 
}

// call for check & verify your number with Code
console.log(await nvbm.codeExist("exampleNumber", "exampleCode", "exampleDeviceID")) // if verifyed: true, else: false

License βš–οΈ

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.