Bcryptjs will fail to match after 2 times of encryption.

  node.js, question

Because bcrypt installation has been in gyp .. so I used bcryptjs.
I encrypted the password registered and entered by the user at the front desk, and encrypted it after receiving it at the back desk, which will cause the user’s login password to not match. . . Is my writing wrong, or is this the way it is?

This is the foreground encryption logic

bcrypt.genSalt(10, (err, salt) => {
 if (err) {
 console.log(err)
 } else {
 bcrypt.hash(this.password, salt, (err, hash) => {
 if (err) {
 console.log(err)
 } else {
 this.$http
 Post(config.dev.host plus' /user/login', {.
 username: this.username,
 password: hash
 })
 .then((data) => {
 console.log(data)
 }, (err) => {
 console.log(err)
 })
 bracket
 })
 bracket

This is the background UserSchema method.

User.pre('save', function (next) {
 if (!  this.isNew) {
 this.meta.updateAt = Date.now();
 bracket
 var user = this;
 bcrypt.genSalt(10, function (err, salt) {
 if (err) {
 next(err);
 } else {
 bcrypt.hash(user.password, salt, function (err, hash) {
 if (err) {
 next(err);
 } else {
 Console.log(user.username plus'' plus user.password plus'' plus hash);
 user.password = hash;
 next();
 bracket
 })
 bracket
 })
 });
 
 User.methods = {
 comparePassword: function (_password, cb) {
 var user = this;
 bcrypt.compare(_password, user.password, function (err, isMatched) {
 console.log(_password)
 console.log(user.password)
 if (err) {
 cb(err);
 } else {
 cb(null, isMatched);
 bracket
 })
 bracket
 bracket

The front desk does not need encryption.