kopia lustrzana https://github.com/c9/core
Only load bcrypt when it's required, so vfs doesn't complain about incompatible binaries
rodzic
285fe0b2c3
commit
82b9960977
|
@ -6,15 +6,21 @@
|
||||||
|
|
||||||
var hashing = require('./hashing');
|
var hashing = require('./hashing');
|
||||||
var bcrypt;
|
var bcrypt;
|
||||||
try {
|
|
||||||
bcrypt = require('bcrypt');
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to load brcrypt - binary version mismatch?", e.stack);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
var SALT_LENGTH = 8;
|
var SALT_LENGTH = 8;
|
||||||
|
|
||||||
|
function loadBcrypt() {
|
||||||
|
if (bcrypt) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
bcrypt = require('bcrypt');
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to load bcrypt - binary version mismatch?", e.stack);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.encrypt = function(password, callback) {
|
exports.encrypt = function(password, callback) {
|
||||||
|
loadBcrypt();
|
||||||
var passwordHashed = hashing.md5(password);
|
var passwordHashed = hashing.md5(password);
|
||||||
bcrypt.hash(passwordHashed, SALT_LENGTH, function(err, passwordEncrypted) {
|
bcrypt.hash(passwordHashed, SALT_LENGTH, function(err, passwordEncrypted) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
@ -23,6 +29,7 @@ exports.encrypt = function(password, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.compare = function(password, encrypted, callback) {
|
exports.compare = function(password, encrypted, callback) {
|
||||||
|
loadBcrypt();
|
||||||
var passwordHashed = hashing.md5(password);
|
var passwordHashed = hashing.md5(password);
|
||||||
if (passwordHashed == encrypted) { // Some passwords may still only be hashed, not bcrypted, so see if that worked first.
|
if (passwordHashed == encrypted) { // Some passwords may still only be hashed, not bcrypted, so see if that worked first.
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
|
|
Ładowanie…
Reference in New Issue