Ich bin sehr neu zu Nodejs/Mongo (mit Mungo). Ich verwende das bcrypt-Modul, um das Passwort aus einem HTML-Formular zu hashen. In meiner Funktion db.create kann ich die Variable storehash nicht in mongodb speichern.Nodejs, bcrypt, Mungo
Ich bekomme keine Fehler, aber es ist nur leer in der Datenbank. Ich habe jede zweite Zeile des Codes überprüft und es scheint zu funktionieren. Ich verstehe nicht, warum ich nicht in der Lage bin, eine Variable als "Passwort: Storehash" zu speichern, während ich etwas wie "Passwort: 'Test'" speichern kann.
Ich bin mir sicher, dass ich etwas mache noob Fehler irgendwo. Ich würde mich über jede Hilfe freuen!
var db = require('../models/users.js');
var bcrypt = require('bcryptjs');
module.exports.createuser = function(req,res){
\t var pass = req.body.password;
\t var storehash;
\t //passsord hashing
\t bcrypt.genSalt(10, function(err,salt){
\t \t if (err){
\t \t \t return console.log('error in hashing the password');
\t \t }
\t \t bcrypt.hash(pass, salt, function(err,hash){
\t \t \t if (err){
\t \t \t \t return console.log('error in hashing #2');
\t \t \t } else {
\t \t \t \t console.log('hash of the password is ' + hash);
\t \t \t \t console.log(pass);
\t \t \t \t storehash = hash;
\t \t \t \t console.log(storehash);
\t \t \t }
\t \t });
\t });
db.create({
email: req.body.email,
username: req.body.username,
password: storehash,
}, function(err, User){
\t if (err){
\t \t console.log('error in creating user with authentication');
\t } else {
\t \t console.log('user created with authentication');
\t \t console.log(User);
\t }
}); //db.create
};// createuser function
Codebeispiele! – num8er
Verwenden Sie den Code-Formatierer, der von SO zur Verfügung gestellt wird, nicht Bilder des Codes –
haha ich denke, ich habe gerade das getan. Vielen Dank! –