mirror of
https://github.com/BradNut/node-auth
synced 2025-09-08 17:40:17 +00:00
Hashing password and salting.
This commit is contained in:
parent
3b15223b1d
commit
dae6e0761a
4 changed files with 36 additions and 2 deletions
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
|||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcryptjs": "^2.4.3",
|
||||
"dotenv": "^8.2.0",
|
||||
"fastify": "^3.12.0",
|
||||
"fastify-static": "^4.0.1",
|
||||
|
|
@ -80,6 +81,11 @@
|
|||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"node_modules/bcryptjs": {
|
||||
"version": "2.4.3",
|
||||
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||
"integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms="
|
||||
},
|
||||
"node_modules/bl": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
||||
|
|
@ -938,6 +944,11 @@
|
|||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"bcryptjs": {
|
||||
"version": "2.4.3",
|
||||
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||
"integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms="
|
||||
},
|
||||
"bl": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"author": "Bradley Shellnut",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcryptjs": "^2.4.3",
|
||||
"dotenv": "^8.2.0",
|
||||
"fastify": "^3.12.0",
|
||||
"fastify-static": "^4.0.1",
|
||||
|
|
|
|||
17
src/accounts/register.js
Normal file
17
src/accounts/register.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import bcrypt from 'bcryptjs'
|
||||
const { genSalt, hash } = bcrypt
|
||||
|
||||
export async function registerUser(email, password) {
|
||||
// generate salt
|
||||
const salt = await genSalt(10)
|
||||
console.log('salt', salt)
|
||||
|
||||
// hash with salt
|
||||
const hashedPassword = await hash(password, salt)
|
||||
console.log('hashedPassword', hashedPassword)
|
||||
|
||||
// store in database
|
||||
|
||||
// return user from database
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import fastifyStatic from 'fastify-static'
|
|||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { connectDb } from './db.js'
|
||||
import { registerUser } from './accounts/register.js'
|
||||
|
||||
// ESM specific "features"
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
|
|
@ -17,8 +18,12 @@ async function startApp() {
|
|||
root: path.join(__dirname, "public"),
|
||||
})
|
||||
|
||||
app.post('/api/register', {}, (request, reply) => {
|
||||
console.log('request', request.body.email, request.body.password);
|
||||
app.post('/api/register', {}, async (request, reply) => {
|
||||
try {
|
||||
await registerUser(request.body.email, request.body.password)
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
})
|
||||
|
||||
// app.get("/", {}, (request, reply) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue