atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
974 stars 91 forks source link

Add `hashPassword()` and `verifyPassword()` server utils #155

Closed atinux closed 1 month ago

atinux commented 2 months ago
// import is optional
import { hashPassword, verifyPassword } from '#auth-utils'

const hash = hashPassword('user_password')
// $2a$10$vEdoE9pqBlkJMqWmbk1JWuEYbJoansodgPo7a2GBkXsO8SleGXCr6

if (verifyPassword(existingHash, plainTextValue)) {
  // password is correct
}

Demo from bcrypt-edge on https://github.com/atinux/nuxt-bcrypt-edge

The second argument of hashPassword is the same as hashSync

const hash = hashPassword('use_password', 12)