'use strict';

var bcrypt = require('bcrypt');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// export a mongoose model

var userSchema = new Schema({
	userName : String,
	passwordDigest : String
});

userSchema.virtual('password').set(function(password) {
	var self = this;

	var saltPromise = new Promise(function saltExec(res, rej) {
		bcrypt.genSalt(16, function(err, salt) {
			if(err) {
				rej(err);
				return;
			}

			res(salt);
		});
	});

	var returnedPromise = saltPromise.then(function(salt) {
		return new Promise(function hashExec(res, rej) {
			bcrypt.hash(password, salt, function(err, digest) {
				if(err) {
					rej(err);
					return;
				}

				res(digest);
			});
		});
	}).then(function(digest) {
		self.passwordDigest = digest;
	});

	return returnedPromise;
});

module.exports = userSchema;

@@ -229,32 +229,30 @@
 ema.
-virtual('password').set(
+methods.setPassword = 
 func
@@ -764,16 +764,38 @@
 digest;%0A
+%09%09return self.save();%0A
 %09%7D);%0A%0A%09r
@@ -818,17 +818,16 @@
 omise;%0A%7D
-)
 ;%0A%0Amodul

Change virtual prop to an instance method