1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01: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) {
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();
apiService.postToken(request, function (response) {
if (!response || !response.token) {
return;
}
var deferred = $q.defer();
apiService.postToken(request, function (response) {
if (!response || !response.token) {
return;
}
tokenService.setToken(response.token, function () {
cryptoService.setKey(key, function () {
userService.setUserProfile(response.profile, function () {
deferred.resolve(response);
tokenService.setToken(response.token, function () {
cryptoService.setKey(key, function () {
userService.setUserProfile(response.profile, function () {
deferred.resolve(response);
});
});
});
}, function (error) {
deferred.reject(error);
});
}, function (error) {
deferred.reject(error);
});
return deferred.promise;
return deferred.promise;
});
};
_service.logInTwoFactor = function (code, provider) {

View File

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