5

Hi everybody I try use hash in password model but if i try save a new user adonis send me this error :

Error: Cannot find module 'phc-argon2'

I find in official documentation of adonis but i not found some solution...

this is my model :

import { DateTime } from 'luxon'
import { BaseModel, column, beforeSave, hasOne, HasOne } from '@ioc:Adonis/Lucid/Orm'
import Hash from '@ioc:Adonis/Core/Hash'
import Profile from 'App/Models/Profile'
import Myvericode from 'App/Models/Myvericode'

export default class User extends BaseModel {
  @column({ isPrimary: true })
  public id: number

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime

  @column()
  public name : string
  
  @column()
  public username : string
  
  @column({ serializeAs: null })
  public password : string

  @column()
  public phonenumber:string

  @column()
  public email : string
  
  @column()
  public isverifiedemail : number

  @hasOne(() => Profile)
  public profile: HasOne<typeof Profile>

  @hasOne(() => Myvericode)
  public vericode: HasOne<typeof Myvericode>

  @beforeSave()
  public static async hashPassword (user: User) {
    if (user.$dirty.password) {
      user.password = await Hash.hash(user.password)
    }
  }

}
I try npm i phc-argon2 and not work I using Linux operative system, thanks for de answers
Gario3
  • 139
  • 2
  • 13

2 Answers2

15

In config/hash.ts has the steps of installation of encryptor who you want to use. Here you can set your driver: default: Env.get('HASH_DRIVER', 'bcrypt') then you can simply install the required driver who wanted

for argon2 npm install phc-argon2

for bcrypt npm install phc-bcrypt

is had worked for me

João Victor
  • 161
  • 1
  • 4
3

There is note for breaking change in the docs:

Earlier the argon2 and bcrypt drivers were relying on the following packages.

@phc/argon2
@phc/bcrypt

However, these packages are not actively maintained and had some security vulnerabilities. We have forked and published them as phc-bcrypt and phc-argon2. So make sure to remove old dependencies from your application in favor of the new ones.

more here: https://preview.adonisjs.com/releases/core/preview-rc-1_7/#hash

Kindly check for your adonis 5(specifically the core and auth) version if you're affected

crrmacarse
  • 1,176
  • 1
  • 8
  • 22