Ejemplo n.º 1
0
	encryptPassword: function(password) {
		var salt = bcrypt.genSaltSync(SALT_WORK_FACTOR);
		return bcrypt.hashSync(password, salt);
	},
Ejemplo n.º 2
0
function encryptPassword(password) {
    var salt = bcrypt.genSaltSync(10);
    return bcrypt.hashSync(password, salt);
}
Ejemplo n.º 3
0
 strCryptSync: function(str, saltLen) {
   if (undefined == saltLen) {
     saltLen = 10;
   }
   return bcrypt.hashSync(str, bcrypt.genSaltSync(saltLen));
 },
Ejemplo n.º 4
0
function strCryptSync(str) {
    return bcrypt.hashSync(str, bcrypt.genSaltSync(10));
}
Ejemplo n.º 5
0
/* GLOBAL REQUIRES: See `../server.js` */ 
const pgp         = require('pg-promise')({});
const bcrypt      = require('bcrypt');
const salt        = bcrypt.genSaltSync(10);
require('dotenv').config();

/* Connection to our back-end postgreSQL database */
const cn = {
    host: 'localhost', // 'localhost' is the default
    port: 5432, // 5432 is the default
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD
};

/* Create link from PGP to our database */
const db = pgp(cn)

/* CREATESECURE: Uses bcrypt, hash, salt, to create hash for database storage */
function createSecure(email, password, callback){
  bcrypt.genSalt(password, salt, function(err, hash){
    bcrypt.hash(password, salt, function(err, hash) {
      callback(email, hash)
    })
  })
}

/* Creates user from HTML input fields and stores them in the database using createSecure for password_digest */
function createUser(req, res, next) {
  createSecure(req.body.email, req.body.password, saveUser)
  // saveUser: Query to store user in database 
Ejemplo n.º 6
0
exports.saveStaff = function(req,res,next){
    console.log("saveStaff。。。");
    //开始校验输入数值的正确性
    var store_id = req.body.store_id;
    var pet_name = req.body.pet_name;//
    var cellphone = req.body.cellphone;//
    var role_id = req.body.role_id;//
    var state = req.body.state;//
    var sex = sanitize(req.body.sex).ifNull(1);
    var birthday = sanitize(req.body.birthday).ifNull(getNow());
    var due_time = req.body.due_time;//
    var user_id = req.body.user_id;
    var privacy = sanitize(req.body.privacy).ifNull(0);
    var point = sanitize(req.body.point).ifNull(0);
    var savings = sanitize(req.body.savings).ifNull(0);
    var comment = sanitize(req.body.comment).ifNull("");

    var ep = EventProxy.create();

    //当有异常发生时触发
    ep.once('error', function(result) {
        ep.unbind();//remove all event
        return res.json(result.error, result.status);
    });

    ep.on('creatStaff', function(staff) {
        creatStaff(staff);
    });

    ep.on('creatStoreStaff', function(staff) {
        creatStoreStaff(staff);
    });

    ep.on('addUserContent', function(staff) {
        addUserContent(staff);
    });

    //回调函数
    function feedback(result) {
        res.json(result, 201);
    };

    function creatStaff(staff){
        Member.create(staff, function(err, info){
            if(err) return next(err);
            if(!info || !info.insertId) ep.trigger('error', {status:500, error:'创建员工出错。'});
            staff._id = info.insertId;
            ep.trigger("creatStoreStaff", staff);
            //ep.trigger("addUserContent", staff);//
        });
    };

    function addUserContent(staff){
        User.findOne({_id:staff.user_id}, function(err, user){
            if(err) return next(err);
            if(!user) ep.trigger('error', {status:400, error:'未找到当前会员的User信息。'});
            staff.user = user;
            feedback({staff:staff});
        });
    };

    function creatStoreStaff(staff){
        StoreStaff.create({member_id:staff._id, store_id:store_id}, function(err, info){
            if(err) return next(err);
            //if(!info || !info.insertId) ep.trigger('error', {status:500, error:'创建员工-门店映射关系出错。'});
            staff.storestaff = {member_id:staff._id, store_id:store_id};
            ep.trigger("addUserContent", staff);
        });
    }


    try {
        check(store_id, "保存失败,门店不能为空!").notNull();
        check(pet_name, "保存失败,昵称不能为空!").notNull();
        check(cellphone, "保存失败,手机号码不能为空!").notNull();
        check(role_id, "保存失败,角色不能为空!").notNull();
        check(state, "保存失败,状态不能为空!").notNull();
        check(due_time, "保存失败,到期时间不能为空!").notNull();

        if(req.session.user.member.org_id){
            //判断是否需要新建user
            if(user_id){
                //不需要新建用户
                ep.trigger("creatStaff", {"user_id":user_id, "org_id":req.session.user.member.org_id, "pet_name":pet_name, "privacy":privacy,
                    "point":point, "savings":savings, "comment":comment, "role_id":role_id, "state":state, "create_time":getNow(), "due_time":due_time});
            }else{
                //新建用户,创建默认密码并对密码进行加密
                var salt = bcrypt.genSaltSync(10);
                var pass = bcrypt.hashSync("123456", salt);
                User.create({"name":pet_name, "pet_name":pet_name, "cellphone":cellphone, "password":pass, "state":"1", "sex":sex, "birthday":birthday, "create_time":getNow()}, function(err, info){
                    if(err) return next(err);
                    ep.trigger("creatStaff", {"user_id":info.insertId, "org_id":req.session.user.member.org_id, "pet_name":pet_name, "privacy":privacy,
                        "point":point, "savings":savings, "comment":comment, "role_id":role_id, "state":state, "create_time":getNow(), "due_time":due_time});
                });
            }
        }else{
            ep.trigger('error', {status:400, error:'获取当前用户所属商户失败。'});
        }
    }catch(e){
        res.json({status:400, error:e.message}, 400);
    }
};
Ejemplo n.º 7
0
exports.passwordHash = function (password) {
  var salt = bcrypt.genSaltSync(10);
  var hash = bcrypt.hashSync(password, salt);
  return hash;
};
module.exports = (password) => {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null)
};
Ejemplo n.º 9
0
  resolve: async (source, { email, password }) => {
    const salt = bcrypt.genSaltSync();
    const hash = bcrypt.hashSync(password, salt);
    const errors = [];
    let token = null;
    let user = null;

    if (password.length < 8) {
      errors.push({
        key: 'password', message: 'Password must be at least 8 letter long',
      });
    }

    const count = await User.count({ where: { email } });

    if (count > 0) {
      errors.push({
        key: 'email', message: 'User with this email already exists',
      });
    }

    if (errors.length === 0) {
      user = await User.create({
        email,
        passwordHash: hash,
        status: 0,
      });

      token = jwt.sign({ id: user.id }, auth.jwt.secret, { expiresIn: auth.jwt.expires });
      user = await User.findOne({
        where: { email },
        include: [
          {
            model: UserInfo,
            include: [Country],
          },
          {
            model: Language,
            as: 'languages',
          },
          {
            model: Institution,
            as: 'institutions',
            include: [
              { model: InstitutionTypeModel },
              {
                model: City,
                include: [
                  { model: Country },
                ],
              },
            ],
          },
        ],
      });
    }

    const data = {
      user,
      token,
    };

    return {
      data,
      errors,
    }
  },
router.get('/salt', function(req, res, next) {
  var salt = bcrypt.genSaltSync(10);
  var result = salt;
  res.render('index', { title: 'Encryption', result: result });
});
router.get('/hash', function(req, res, next) {
  var pass = '******';
  var salt = bcrypt.genSaltSync(10);
  var hash = bcrypt.hashSync(pass, salt);
  res.render('index', { title: 'Encryption', result: hash });
});
Ejemplo n.º 12
0
app.get('/nsepass', function (req, res) {

  res.send(bCrypt.hashSync("nse", bCrypt.genSaltSync(10), null));

});
Ejemplo n.º 13
0
 .set(function(password) {
   var salt = this.salt = bcrypt.genSaltSync(10);
   this.hash = bcrypt.hashSync(password, salt);
 })
Ejemplo n.º 14
0
var BcryptHash = function(str){
	var salt = bcrypt.genSaltSync(10);  
	return bcrypt.hashSync(str, salt);
}
Ejemplo n.º 15
0
function changePassword( username, password ) {
	var salt = crypt.genSaltSync( 10 );
	var hash = crypt.hashSync( password, salt );
	return users.changePassword( username, salt, hash );
}
Ejemplo n.º 16
0
exports.encodePassoword = function(plainPassword) {
    var salt = bycrypt.genSaltSync(10);
    var hash = bycrypt.hashSync(plainPassword, salt);

    return hash
}
Ejemplo n.º 17
0
function createUser( username, password ) {
	var salt = crypt.genSaltSync( 10 );
	var hash = crypt.hashSync( password, salt );
	return users.create( username, salt, hash );
}
Ejemplo n.º 18
0
 beforeCreate: user => {
     const salt = bcrypt.genSaltSync();
     user.password = bcrypt.hashSync(user.password, salt);
 }
Ejemplo n.º 19
0
userSchema.methods.generateHash = function(password) {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
Ejemplo n.º 20
0
UserSchema.virtual('password').set(function(password) {
  this._password = password;
  var salt = this.salt = bcrypt.genSaltSync();
  this.hash = bcrypt.hashSync(password, salt);
}).get(function() {
userSchema.pre('save', function(next) {
	console.log('here!');
  this.password = bcrypt.hashSync(this.password, bcrypt.genSaltSync(10));
  console.log(this.password);
  next();
});
Ejemplo n.º 22
0
var bcrypt = require('bcrypt'),
		salt = bcrypt.genSaltSync(10), // generate salt(10 chars), but hide this num
		passport = require('passport'),// genSaltSync() is a bcrypt method
		passportLocal = require('passport-local');

module.exports = function User (sequelize, DataTypes){
	var User = sequelize.define('user', {
		username: {
			type: DataTypes.STRING,
			unique: true,
			validate: {len: [6,30]}
		},
		password: {
			type: DataTypes.STRING,
			validate: {notEmpty: true}
			},
		firstname: DataTypes.STRING,
		lastname: DataTypes.STRING,
		phone: DataTypes.STRING,
		zip: DataTypes.INTEGER,
		match: DataTypes.INTEGER,
		cuisine: DataTypes.ARRAY(DataTypes.STRING),
  	hobbies: DataTypes.ARRAY(DataTypes.STRING),
  	stores: DataTypes.ARRAY(DataTypes.STRING),
  	books: DataTypes.ARRAY(DataTypes.STRING),
  	clothes: DataTypes.ARRAY(DataTypes.STRING),
  	art: DataTypes.ARRAY(DataTypes.STRING),
  	color: DataTypes.ARRAY(DataTypes.STRING),
  	animals: DataTypes.ARRAY(DataTypes.STRING),
  	metal: DataTypes.ARRAY(DataTypes.STRING),
  	elements: DataTypes.ARRAY(DataTypes.STRING)
Ejemplo n.º 23
0
userController.encryptPassword = (user) => {
  const salt = bcrypt.genSaltSync(SALT_FACTOR);
  const hash = bcrypt.hashSync(user.password, salt);
  user.password = hash;
};
Ejemplo n.º 24
0
 var createHash = function(password){
     console.log(password)
     return bCrypt.hashSync(password, bCrypt.genSaltSync(10));
 }
Ejemplo n.º 25
0
}).set(function(password) {
  this._password = password;
  salt = this.salt = bcrypt.genSaltSync(10);
  this.hash = bcrypt.hashSync(password, salt);
});
Ejemplo n.º 26
0
 makeSalt: function() {
   return bcrypt.genSaltSync(SALT_WORK_FACTOR);
 },
Ejemplo n.º 27
0
var bcrypt = require("bcrypt");
var salt = bcrypt.genSaltSync(10);

module.exports = function (sequelize, DataTypes){
  var User = sequelize.define('User', {
    email: { 
      type: DataTypes.STRING, 
      unique: true, 
      validate: {
        len: [6, 30],
      }
    },
    password: {
      type:DataTypes.STRING,
      validate: {
        notEmpty: true
      }
    }
  },

  {
    associate: function(models){
      this.hasMany(models.Favorite);
    
    },
    instanceMethods: {
      checkPassword: function(password) {
        return bcrypt.compareSync(password, this.password);
      }
    },
    classMethods: {
Ejemplo n.º 28
0
 userSchema.pre('save', function(next) {
   this.password = bcrypt.hashSync(this.pasword, bcrypt.genSaltSync(10));
   next();
 });
Ejemplo n.º 29
0
 .set(function(password) {
   this._password = password;
   this.hashed_password = BCrypt.hashSync(password, BCrypt.genSaltSync(10), null);
 })
Ejemplo n.º 30
0
function encryptPass(pass, type)
{
    var salt = bcrypt.genSaltSync(10);
    //console.log('encrypt for '+ pass+type);
    return bcrypt.hashSync(pass+type, salt);
}