1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-03 04:59:06 +02:00

hashpassword with callback

This commit is contained in:
Kyle Spearrin 2016-09-05 00:03:49 -04:00
parent 8f0a24b1b9
commit cc67d12c57
2 changed files with 27 additions and 23 deletions

View File

@ -6,26 +6,28 @@
_service.logIn = function (email, masterPassword) { _service.logIn = function (email, masterPassword) {
var key = cryptoService.makeKey(masterPassword, email); var key = cryptoService.makeKey(masterPassword, email);
var request = new TokenRequest(email, cryptoService.hashPassword(masterPassword, key)); cryptoService.hashPassword(masterPassword, key, function (hashedPassword) {
var request = new TokenRequest(email, hashedPassword);
var deferred = $q.defer(); var deferred = $q.defer();
apiService.postToken(request, function (response) { apiService.postToken(request, function (response) {
if (!response || !response.token) { if (!response || !response.token) {
return; return;
} }
tokenService.setToken(response.token, function () { tokenService.setToken(response.token, function () {
cryptoService.setKey(key, function () { cryptoService.setKey(key, function () {
userService.setUserProfile(response.profile, function () { userService.setUserProfile(response.profile, function () {
deferred.resolve(response); deferred.resolve(response);
});
}); });
}); });
}, function (error) {
deferred.reject(error);
}); });
}, function (error) {
deferred.reject(error);
});
return deferred.promise; return deferred.promise;
});
}; };
_service.logInTwoFactor = function (code, provider) { _service.logInTwoFactor = function (code, provider) {

View File

@ -67,17 +67,19 @@ function initCryptoService() {
return key; return key;
}; };
CryptoService.prototype.hashPassword = function (password, key) { CryptoService.prototype.hashPassword = function (password, key, callback) {
if (!key) { this.getKey(false, function (storedKey) {
key = this.getKey(); if (!key) {
} key = storedKey;
}
if (!password || !key) { if (!password || !key) {
throw 'Invalid parameters.'; throw 'Invalid parameters.';
} }
var hashBits = sjcl.misc.pbkdf2(key, password, 1, 256, null); var hashBits = sjcl.misc.pbkdf2(key, password, 1, 256, null);
return sjcl.codec.base64.fromBits(hashBits); callback(sjcl.codec.base64.fromBits(hashBits));
});
}; };
CryptoService.prototype.getAes = function (callback) { CryptoService.prototype.getAes = function (callback) {