Node Crypto

Learnings from working with crypto in Node.js.

Generating strings

Using nanoid you can create "secure" strings.

npx nanoid-cli --size 32

Hashing passwords

bcrypt is a library that helps you hash passwords without maintaining a secret key.

import bcrypt from 'bcrypt'

async function someAuthFunction () {
  // Compare the users password hash to the incoming one
  const match = await bcrypt.compare(password, passwordFromDb)

  // Create a hash from the incoming plain text password with 10 salt rounds
  const newHash = await bcrypt.hash(plaintext, 10)
}

Content properties

  • Type: Note
  • Category: JavaScript
  • Tags: backend, javascript
  • Custom slug: None

This is a preview of a simpler page design that I'm working on over the next little bit. I've finally added a (click it!) but there's still a few pages left to be converted so don't worry if things don't look quite right just yet 🙏

Content on blog pages use the CC-BY-SA license. The source code and notes use the MIT license. Unsure? Mention me on Mastodon.