2017-12-12 3 views
0

私はbcryptに問題があります。なぜそれがわからないのですか?ここでは基本登録ルートのための私のコードは次のとおりです。Bcrypt不正な引数:番号

const express = require('express'); 
const router = express.Router(); 
const bcrypt = require('bcryptjs'); 
const passport = require('passport'); 

// Register 
router.post('/register', function(req, res){ 

    req.checkBody('username', 'Username is Required').notEmpty(); 
    req.checkBody('kingname', 'Kingdom Name is Required').notEmpty(); 
    req.checkBody('email', 'E-Mail is Required').notEmpty(); 
    req.checkBody('password', 'Password is Required').notEmpty(); 
    req.checkBody('password2', 'Passwords do not match').equals(req.body.password); 

    var errors = req.validationErrors(); 

    if(errors) { 
    res.render('index', { 
     errors: errors 
    }); 
    } else { 
    var newUser = { 
     username: req.body.username, 
     kingname: req.body.kingname, 
     email: req.body.email, 
     password: req.body.password, 
     password2: req.body.password2 
    } 

    bcrypt.getSalt(10, function(err, salt){ 
    bcrypt.hash(newUser.password, salt, function(err, hash){ 
     if(err) { 
     console.log(err); 
     } 
     newUser.password = hash; 
     let post = {username: newUser.username, password: newUser.password, email: newUser.email, kingname: newUser.kingname}; 
     let sql ='INSERT INTO users SET ?'; 
     let query = db.query(sql, post, function(err, res){ 
     if(err) { 
      console.log(err); 
      return; 
     } else { 
     user_id = res.insertID; 
     console.log('Last User ID', res.insertID); 
     console.log('User registration successful...'); 
     res.redirect('/'); 
     } 
     }); 
    }); 
    }); 
    } 
}); 

module.exports = router; 

今、私は取得していますエラーは、このです:

Error: Illegal arguments: number 
    at Object.bcrypt.getSalt (/home/kogadmin/www/node_modules/bcryptjs/dist/bcrypt.js:339:19) 
    at /home/kogadmin/www/routes/reg.js:30:10 
    at Layer.handle [as handle_request] (/home/kogadmin/www/node_modules/express/lib/router/layer.js:95:5) 
    at next (/home/kogadmin/www/node_modules/express/lib/router/route.js:137:13) 
    at Route.dispatch (/home/kogadmin/www/node_modules/express/lib/router/route.js:112:3) 
    at Layer.handle [as handle_request] (/home/kogadmin/www/node_modules/express/lib/router/layer.js:95:5) 
    at /home/kogadmin/www/node_modules/express/lib/router/index.js:281:22 
    at Function.process_params (/home/kogadmin/www/node_modules/express/lib/router/index.js:335:12) 
    at next (/home/kogadmin/www/node_modules/express/lib/router/index.js:275:10) 
    at Function.handle (/home/kogadmin/www/node_modules/express/lib/router/index.js:174:3) 

私は少し混乱している理由です。エラーがどのように見えるかは、10が不正な引数であると言っていることです。そうではありません。私は構文がドキュメントから正しいことを確認しました。

+0

を持っているように、getSaltないgenSaltすべきではありません見えますか? – WakeskaterX

+0

ありがとうございました:)私はgenSaltとして読んでいましたが、私はその行を何度か読み返しました。そのような悪いnoobコーダー:P – William

答えて

1

私は

genSalt(10, function() {}) 

する必要がありますかなり確信しているあなたはタイプミス:)

+0

ちっちゃな、私はそれをしたことを誓った可能性があります。私はそれを読んで、それをgenSaltとして読んでいました。ありがとうございました! – William

+0

心配はいりません!時には、最も簡単なことは見つけにくいバグです! – WakeskaterX

関連する問題