adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
193 stars 65 forks source link

[V5] Auth attempt error. #151

Closed remidosol closed 3 years ago

remidosol commented 4 years ago

Package version

@adonisjs/ace: ^6.0.0, @adonisjs/auth: ^4.2.4, @adonisjs/core: ^5.0.0-preview-rc, @adonisjs/fold: ^6.0.0 @adonisjs/lucid: ^8.2.2

Node.js and npm version

Node: v14.5.0 npm: v6.14.6

Sample Code (to reproduce the issue)

My controller function:

public async login ({ request, auth, response }: HttpContextContract) {

    try {
      const { email, password } = request.only(['email', 'password'])

      await request.validate(LogInValidator)

      try {
        const token = await auth.use('api').attempt(email, password) // Error Here
        const tokJson = token.toJSON() 
        return response.status(200).json({
          message: 'Logging in is successful',
          data: tokJson,
        })
      } catch (error) {
        return response.status(500).json({
          message: error.message,
          stack: error.stack
        })
      }

    } catch (error) {
      return response.status(400).json({
        messages: error.messages
      })
    }
  }

I use POST Method for this process. The request body that I sent as JSON:

{
    "email": "remidosola@hotmail.com",
    "password": "remidosol4434"
}
My available row in MySQL:   3 remidosola@hotmail.com remidosol Company corporate_user $argon2id$... 900651649451 Beleş Malatya Province Malatya Malatya Malatya'da bir yer 00000000000 pending   2020-09-18 03:59:47 2020-09-18 03:59:47

The error which I got:

{
    "message": "params values must satisfy /^[a-zA-Z0-9/+.-]+$/",
    "stack": "TypeError: params values must satisfy /^[a-zA-Z0-9/+.-]+$/\n    at Object.deserialize 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@phc\\format\\index.js:200:13)\n    at Object.verify 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\phc-argon2\\index.js:200:18)\n    at Argon.verify 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\hash\\build\\src\\Drivers\\Argon.js:62:37)\n    at Hash.verify 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\hash\\build\\src\\Hash\\index.js:125:27)\n    at LucidUser.verifyPassword 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\auth\\build\\src\\UserProviders\\Lucid\\User.js:46:23)\n    at OATGuard.verifyPassword 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\auth\\build\\src\\Guards\\Base\\index.js:78:45)\n    at OATGuard.verifyCredentials 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\auth\\build\\src\\Guards\\Base\\index.js:134:20)\n    at processTicksAndRejections 
(internal/process/task_queues.js:93:5)\n    at OATGuard.attempt 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\auth\\build\\src\\Guards\\Oat\\index.js:207:22)\n    at AuthController.login 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\app\\Controllers\\Http\\AuthController.ts:25:23)\n    at Object.PreCompiler.runRouteHandler [as fn] 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\http-server\\build\\src\\Server\\PreCompiler\\index.js:46:31)\n    at Server.handle 
(C:\\Users\\ibo86\\Desktop\\Projeler vs\\Back-End\\AdonisV5\\mockingBird\\node_modules\\@adonisjs\\http-server\\build\\src\\Server\\index.js:138:13)"
}
thetutlage commented 4 years ago

First, it can be created as discussion and 2nd the issues should go to the correct repo.

thetutlage commented 4 years ago

Is the password hashed using the AdonisJS Hash module? And also what is the length of the password column in the database.

remidosol commented 4 years ago

Is the password hashed using the AdonisJS Hash module? And also what is the length of the password column in the database.

Yes, password hashed:

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

And the length and type of the password column is VARCHAR(254).

thetutlage commented 4 years ago

Can you share the complete password hash here?

remidosol commented 4 years ago

Can you share the complete password hash here?

$argon2id$v=19$t=3;m=4096;p=1$AJZYQsiwc6GPLx++WBmAZw$nOz9R7mevmVIGHaOsMsqzFAb7sJKLufmmNbQByZSAMs

thetutlage commented 4 years ago

Can you share the config/hash.ts file contents. Coz the hash generated by the AdonisJS hash module uses , as a separator and not the ;. There seems to be something weird

thetutlage commented 3 years ago

Closing since no response from the issue reporter and not actionable as well