Ich benutze knex, um ein bestimmtes Benutzerpasswort aus meiner Datenbank auszuwählen. Diese Hash-Passwort wird in einem Objekt wie folgt mir zurückgegeben:bcrypt compareSync "Unbehandelte Ablehnung Fehler: Daten und Hash müssen Strings sein"
[anonym { password_hash: '2a $ 10 $ $ zRSFdNJsg8S3Xv1I73gjYuRu.Mw/9Dtujh0dTqrtc9DA12vUHuqbK'}]
Wenn ich bcrypt.compareSync Versuchen Sie es mit vergleichen das eingegebene Passwort und das Passwort, das in der Datenbank existiert, gibt es einen Fehler, der sagt, daß Daten und Raute Zeichenfolgen sein müssen. Ich habe versucht, die .toString() -Methode und JSON.stringify (password_hash). Aber beides hilft nicht. Wie bekomme ich das zum Laufen? Jede Hilfe wird sehr geschätzt. Vielen Dank.
Hier ist mein Code:
knex('users').where({
email: req.body.loginEmail
}).select('password_hash')
.then(function(password_hash) {
//console.log("resp", password_hash)
console.log("JSON stringifies",JSON.stringify(password_hash))
console.log("req", req.body.loginPass)
console.log('hash', password_hash)
bcrypt.compareSync(req.body.loginPass, JSON.stringify(password_hash), function(err, doesMatch){
if (doesMatch){
console.log("Passwords Match")
req.session.email = rows[0].email;
var templateVars = {
emale: req.session.email
}
res.render('/dashboard', templateVars)
} else {
console.log("THIS IS THE ERROR", err);
res.send("I DONT KNOW YOU. SIGN UP FIRSt.")
}
})
})
meine gesamte Fehler
Unhandled rejection Error: data and hash must be strings
at Object.compareSync (/vagrant/CaloBoxInc/node_modules/bcrypt/bcrypt.js:144:15)
at /vagrant/CaloBoxInc/server.js:159:14
at tryCatcher (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)
Könnten Sie einen vollständigen Testfall zum Beispiel mit runkit hinzufügen, der Ihr Problem reproduziert? –
pls, aktualisieren Sie Ihre Frage mit vollem Code. –