Answer the question
In order to leave comments, you need to log in
Why doesn't bcrypt consider a number to be a numeric value?
Good night. Please tell me why, when exporting a variable, bcrypt gives an error that this is not a number, although there is a number in the variable. If I write just a number as a parameter, everything is ok.
Here's the export (packages.js)
const dotenv = require('dotenv')
const initializeDotenv = dotenv.config({path: __dirname + '/.env'})
var path = require('path')
const express = require('express')
const session = require('express-session')
const util = require('util')
const mysql = require('mysql')
const fileStore = require('session-file-store')(session)
const passport = require('passport')
const localStrategy = require('passport-local').Strategy
const bcrypt = require('bcrypt')
//Complex hash for bcrypt
const saltRounds = process.env.COMPLAXITY
module.exports = {dotenv, path, express, session, util, mysql, fileStore, passport, localStrategy, bcrypt, saltRounds}
const { pool } = require('./mysql')
const { bcrypt,saltRounds,dotenv } = require('./packages')
//Create query
class NewQuery {
constructor(type,table,inputs,values,select) {
this.type = type
this.table = table
this.inputs = inputs
this.values = values
this.select = select
this.newQuery = `${this.type} ${this.table} (${this.inputs}) VALUES(${this.values}`
this.send = (password) => {
return new Promise((resolve, reject) => {
pool.query(this.select, (err,res) => {
if (res.length < 1) {
console.log(saltRounds)
bcrypt.genSalt(saltRounds, (err, salt) => {
if(err) console.error(`${err} - salt`)
bcrypt.hash(password, salt, (err, hash) => {
if(err) console.error(`${err} - hash`)
console.log(`${hash} ${salt} ${password} ${saltRounds}`)
pool.query(`${this.newQuery},'${hash}')`, (err,res) => {
if(err) console.error(err)
console.log(`Success: User created! ${this.newQuery} ${hash}`)
})
})
})
}
else {
console.log('Banned: User registered!');
}
})
})
}
}
}
//Create object for query
class CreateQuery {
constructor(type,table,inputs,values,select,password) {
this.type = type
this.table = table
this.inputs = inputs
this.values = values
this.select = select
this.password = password
}
}
module.exports = { NewQuery, CreateQuery}
#Project mode
NODE_ENV=production
#App port
PORT=3000
#Mysql
HOST=localhost
USER=root
PASSWORD=
DATABASE=test
SOCKET=
#Bcrypt
COMPLAXITY=10
#Secret for sessions
SECRET=$$999$$
Answer the question
In order to leave comments, you need to log in
The fastest and preferred way to cast a string to a number is:const saltRounds = +process.env.COMPLAXITY;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question