adonisjs / auth

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

Password mis-match when using auth.attempt(request.input('email'), request.input('password')) #180

Closed yann-yinn closed 2 years ago

yann-yinn commented 2 years ago

I asked on discord before coming here but I had no awnser. I guess i made a mistake but i can't find which one and i'm stuck for hours with this one.

On login, when using await auth.attempt(request.input('email'), request.input('password')) , i'm always having the same error in the following controller : https://github.com/yann-yinn/adonis-starter/blob/e870c764dfe24858cf0b4c683c80d40bb4456f6d/app/Controllers/Http/LoginController.ts#L21

error InvalidCredentialsException: E_INVALID_AUTH_PASSWORD: Password mis-match

But I checked multiple times the email and the password are the ones I entered when creating my account, and I see my password is hashed with argon inside my users table.

Calling directly auth.login method, I got a "invalid credentials error" Any idea what's wrong with my code ?

Strangely, login work just after my account is created (using auth.login(user) inside my signup controller). But after logout, no way to log in again

Package version

  "devDependencies": {
    "@adonisjs/assembler": "^5.3.7",
    "@symfony/webpack-encore": "^1.6.1",
    "adonis-preset-ts": "^2.1.0",
    "pino-pretty": "^7.0.0",
    "typescript": "~4.4",
    "youch": "^2.2.2",
    "youch-terminal": "^1.1.1"
  },
  "dependencies": {
    "@adonisjs/auth": "^8.0.9",
    "@adonisjs/core": "^5.3.4",
    "@adonisjs/lucid": "^16.0.2",
    "@adonisjs/mail": "^7.2.4",
    "@adonisjs/repl": "^3.1.6",
    "@adonisjs/session": "^6.1.2",
    "@adonisjs/shield": "^7.0.6",
    "@adonisjs/view": "^6.1.1",
    "luxon": "^2.0.2",
    "pg": "^8.7.1",
    "phc-argon2": "^1.1.2",
    "proxy-addr": "^2.0.7",
    "reflect-metadata": "^0.1.13",
    "source-map-support": "^0.5.20"
  }

Node.js and npm version

node: v14.17.5 npm: 7.21.0

Sample Code (to reproduce the issue)

BONUS (a sample repo to reproduce the issue)

thetutlage commented 2 years ago

This should go to the discussion forum and not the issues board. We keep issues only for confirmed bugs

thetutlage commented 2 years ago

For now, the error is in your controller. You are assigning the email to the password during signup https://github.com/yann-yinn/adonis-starter/blob/e870c764dfe24858cf0b4c683c80d40bb4456f6d/app/Controllers/Http/SignupController.ts#L37

yann-yinn commented 2 years ago

Oh my god 😅 That's is obviously the issue, god bless you xD