mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
lock with master pass on restart option on PIN lock
This commit is contained in:
@@ -89,7 +89,8 @@ export class SettingsComponent implements OnInit {
|
||||
}
|
||||
this.previousLockOption = this.lockOption;
|
||||
|
||||
this.pin = await this.lockService.isPinLockSet();
|
||||
const pinSet = await this.lockService.isPinLockSet();
|
||||
this.pin = pinSet[0] || pinSet[1];
|
||||
}
|
||||
|
||||
async saveLockOption(newValue: number) {
|
||||
@@ -116,31 +117,55 @@ export class SettingsComponent implements OnInit {
|
||||
|
||||
async updatePin() {
|
||||
if (this.pin) {
|
||||
const pin = await swal({
|
||||
const div = document.createElement('div');
|
||||
const label = document.createElement('label');
|
||||
label.className = 'checkbox';
|
||||
const checkboxText = document.createElement('span');
|
||||
const restartText = document.createTextNode(this.i18nService.t('lockWithMasterPassOnRestart'));
|
||||
checkboxText.appendChild(restartText);
|
||||
label.innerHTML = '<input type="checkbox" id="master-pass-restart" checked>';
|
||||
label.appendChild(checkboxText);
|
||||
div.innerHTML = '<input type="text" class="swal-content__input" id="pin-val">';
|
||||
(div.querySelector('#pin-val') as HTMLInputElement).placeholder = this.i18nService.t('pin');
|
||||
div.appendChild(label);
|
||||
|
||||
const submitted = await swal({
|
||||
text: this.i18nService.t('setYourPinCode'),
|
||||
content: { element: 'input' },
|
||||
content: { element: div },
|
||||
buttons: [this.i18nService.t('cancel'), this.i18nService.t('submit')],
|
||||
});
|
||||
let pin: string = null;
|
||||
let masterPassOnRestart: boolean = null;
|
||||
if (submitted) {
|
||||
pin = (document.getElementById('pin-val') as HTMLInputElement).value;
|
||||
masterPassOnRestart = (document.getElementById('master-pass-restart') as HTMLInputElement).checked;
|
||||
}
|
||||
if (pin != null && pin.trim() !== '') {
|
||||
const kdf = await this.userService.getKdf();
|
||||
const kdfIterations = await this.userService.getKdfIterations();
|
||||
const email = await this.userService.getEmail();
|
||||
const pinKey = await this.cryptoService.makePinKey(pin, email, kdf, kdfIterations);
|
||||
const key = await this.cryptoService.getKey();
|
||||
const pinProtectedKey = await this.cryptoService.encrypt(key.key, pinKey);
|
||||
await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString);
|
||||
if (masterPassOnRestart) {
|
||||
const encPin = await this.cryptoService.encrypt(pin);
|
||||
await this.storageService.save(ConstantsService.protectedPin, encPin.encryptedString);
|
||||
} else {
|
||||
const kdf = await this.userService.getKdf();
|
||||
const kdfIterations = await this.userService.getKdfIterations();
|
||||
const email = await this.userService.getEmail();
|
||||
const pinKey = await this.cryptoService.makePinKey(pin, email, kdf, kdfIterations);
|
||||
const key = await this.cryptoService.getKey();
|
||||
const pinProtectedKey = await this.cryptoService.encrypt(key.key, pinKey);
|
||||
await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString);
|
||||
}
|
||||
} else {
|
||||
this.pin = false;
|
||||
}
|
||||
}
|
||||
if (!this.pin) {
|
||||
await this.storageService.remove(ConstantsService.pinProtectedKey);
|
||||
await this.storageService.remove(ConstantsService.protectedPin);
|
||||
}
|
||||
}
|
||||
|
||||
async lock() {
|
||||
this.analytics.eventTrack.next({ action: 'Lock Now' });
|
||||
await this.lockService.lock();
|
||||
await this.lockService.lock(true);
|
||||
this.router.navigate(['lock']);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user