{"size": 666, "ext": "js", "max_stars_repo_path": "models/methods/instance/user.js", "max_stars_repo_name": "heroicyang/nodediscuss", "max_stars_repo_stars_event_min_datetime": "2015-01-07T06:24:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-13T03:12:51.000Z", "max_issues_repo_path": "models/methods/instance/user.js", "max_issues_repo_name": "Quizp2p/nodediscuss", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/methods/instance/user.js", "max_forks_repo_name": "Quizp2p/nodediscuss", "max_forks_repo_forks_event_min_datetime": "2015-01-29T08:07:04.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-14T01:51:53.000Z"}
{"max_stars_count": 31, "max_issues_count": null, "max_forks_count": 15, "avg_line_length": 19.0285714286, "max_line_length": 77, "alphanum_fraction": 0.6486486486}
/**
 * User 实例方法
 * @author heroic
 */

/**
 * Module dependencies
 */
var crypto = require('crypto');

/**
 * 检查给定的明文密码与数据库密码是否一致
 * @param  {String} plainText   明文密码
 * @return {Boolean}
 */
exports.authenticate = function(plainText) {
  return this.encryptPassword(plainText) === this.passwordHashed;
};

/**
 * 为密码的加密过程提供“加盐”操作
 * @return {String}   随机字串
 */
exports.makeSalt = function() {
  return Math.round((new Date().valueOf() * Math.random())) + '';
};

/**
 * 密码加密
 * @param  {String} password
 * @return {String}   加密后的密码
 */
exports.encryptPassword = function(password) {
  return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
};