Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
allow passing of encoding to utils.crypto and fix password hashing is…
Browse files Browse the repository at this point in the history
…sue in bridge client, update cli with reset-password command
  • Loading branch information
Gordon Hall committed Jun 22, 2016
1 parent c752b98 commit eaa15d4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
35 changes: 35 additions & 0 deletions bin/storj.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ function getKeyRing(callback) {
});
}

function getNewPassword(callback) {
prompt.start();
prompt.get({
properties: {
password: {
description: 'Enter your new desired password',
required: true,
replace: '*',
hidden: true
}
}
}, callback);
}

function getCredentials(callback) {
prompt.start();
prompt.get({
Expand Down Expand Up @@ -233,6 +247,22 @@ var ACTIONS = {
log('info', 'This device has been successfully unpaired.');
});
},
resetpassword: function resetpassword(email) {
getNewPassword(function(err, result) {
PublicClient().resetPassword({
email: email,
password: result.password
}, function(err) {
if (err) {
return log('error', 'Failed to request password reset, reason: %s', [
err.message
]);
}

log('info', 'Password reset request processed, check you email to continue.');
});
});
},
listkeys: function listkeys() {
PrivateClient().getPublicKeys(function(err, keys) {
if (err) {
Expand Down Expand Up @@ -842,6 +872,11 @@ program
.description('revoke this device\'s access your storj api account')
.action(ACTIONS.logout);

program
.command('reset-password <email>')
.description('request an account password reset email')
.action(ACTIONS.resetpassword);

program
.command('list-keys')
.description('list your registered public keys')
Expand Down
6 changes: 3 additions & 3 deletions lib/bridgeclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ BridgeClient.prototype.getContactByNodeId = function(nodeId, callback) {
BridgeClient.prototype.createUser = function(options, callback) {
return this._request('POST', '/users', {
email: options.email,
password: utils.sha256(options.password),
password: utils.sha256(options.password, 'utf8'),
redirect: options.redirect,
pubkey: options.pubkey
}, callback);
Expand Down Expand Up @@ -123,7 +123,7 @@ BridgeClient.prototype.destroyUser = function(options, callback) {
*/
BridgeClient.prototype.resetPassword = function(options, callback) {
return this._request('PATCH', '/users/' + options.email, {
password: utils.sha256(options.password),
password: utils.sha256(options.password, 'utf8'),
redirect: options.redirect
}, callback);
};
Expand Down Expand Up @@ -546,7 +546,7 @@ BridgeClient.prototype._authenticate = function(opts) {
} else if (this._options.basicauth) {
opts.auth = {
user: this._options.basicauth.email,
pass: utils.sha256(this._options.basicauth.password)
pass: utils.sha256(this._options.basicauth.password, 'utf8')
};
}

Expand Down
18 changes: 12 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ var base58 = bitcore.deps.bs58;
/**
* Returns the SHA-256 hash of the input
* @param {String|Buffer} input - Data to hash
* @param {String} encoding - The encoding type of the data
* @returns {String}
*/
module.exports.sha256 = function(input) {
return crypto.createHash('sha256').update(input).digest('hex');
module.exports.sha256 = function(input, encoding) {
return crypto.createHash('sha256').update(input, encoding).digest('hex');
};

/**
* Returns the RIPEMD-160 hash of the input
* @param {String|Buffer} input - Data to hash
* @param {String} encoding - The encoding type of the data
* @returns {String}
*/
module.exports.rmd160 = function(input) {
return crypto.createHash('rmd160').update(input).digest('hex');
module.exports.rmd160 = function(input, encoding) {
return crypto.createHash('rmd160').update(input, encoding).digest('hex');
};

/**
* Returns the RIPEMD-160 SHA-256 hash of this input
* @param {String|Buffer} input - Data to hash
* @param {String} encoding - The encoding type of the data
* @returns {String}
*/
module.exports.rmd160sha256 = function(input) {
return module.exports.rmd160(module.exports.sha256(input));
module.exports.rmd160sha256 = function(input, encoding) {
return module.exports.rmd160(
module.exports.sha256(input, encoding),
encoding
);
};

/**
Expand Down

0 comments on commit eaa15d4

Please sign in to comment.