A demo of hashing and verifying passwords with bcrypt-edge on Cloudflare Workers with Nuxt and NuxtHub.
- Hash & verify a password with bcrypt-edge
- Also works with Scrypt (no dependency needed)
- Server-Side rendering on Cloudflare Workers
Make sure to install the dependencies with pnpm:
pnpm install
Start the development server on http://localhost:3000
:
pnpm dev
Hashing the password ./server/api/hash.post.ts:
import { hashSync } from 'bcrypt-edge/dist/bcrypt-edge'
export default defineEventHandler(async (event) => {
const { password } = await readBody(event)
const hash = hashSync(password, 10)
return { hash }
});
Verifying the password ./server/api/verify.post.ts:
import { compareSync } from 'bcrypt-edge/dist/bcrypt-edge'
export default defineEventHandler(async (event) => {
const { hash, password } = await readBody(event)
const isValid = compareSync(password, hash)
return { isValid }
});
Build the application for production:
pnpm build
Deploy the application on the Edge with NuxtHub on your Cloudflare account:
npx nuxthub deploy
Then checkout your server logs, analaytics and more in the NuxtHub Admin.
You can also deploy using Cloudflare Pages CI.