Module

@admin-bro/passwords

AdminBro feature allowing you to hash passwords in a a given resource.

Installation

To install the passwords feature run:

yarn add @admin-bro/passwords

And install password hashing library if you don't have it yet. I suggest using argon2 or Bcrypt..

yarn add argon2

You can also implement your own hashing function.

Usage

As any feature, you have to pass it to the resource in AdminBroOptions#resources.

In the example below we will use argon2 as a hashing function. We will also use encrypted property from the User model, where we will store the hashed password.

Furthermore, we will hide the encrypted field in the UI. We will do this by the help of the standard PropertyOptions#isVisible

Feature creates virtual password property. You can change that in PasswordsOptions.

const AdminBro = require('admin-bro')
const passwordFeature = require('@admin-bro/passwords')
const argon2 = require('argon2')

// part where you load adapter and models
const User = require('./user')

const options = {
  resources: [{
    resource: User,
    options: {
      properties: { encrypted: { isVisible: false } },
    },
    features: [passwordFeature({
      // PasswordsOptions
      properties: {
        // to this field will save the hashed password
        encryptedPassword: 'encrypted'
      },
      hash: argon2.hash,
    })]
  }]
}

const adminBro = new AdminBro(options)
// and the rest of your app

Options

For the lits of available options take see at PasswordsOptions.

Type Definitions

# HashingFunction(password) → {Promise.<string>|string}

Hashing function used to convert the password

Parameters:
Name Type Description
password string

Password which should be hashed

View Source admin-bro-passwords/src/passwords.feature.ts, line 61

Promise.<string> | string
object

# PasswordsOptions

Options passed to PasswordsFeature

Properties:
Name Type Attributes Description
properties object <optional>

Names of the properties used by the feature

password string <optional>

Virtual property which will be seen by end user. Its value is not stored in the database., Default to password

encryptedPassword string <optional>

Property where encrypted password will be stored. Default to encryptedPassword

hash HashingFunction

Function used to hash the password. You can pass function from the external library, Example using Argon2.: hash: argon2.hash

View Source admin-bro-passwords/src/passwords.feature.ts, line 70