mirror of
https://github.com/pnp/sp-dev-fx-webparts.git
synced 2025-03-02 17:59:15 +00:00
Fixes, if "Change Master" is empty
This commit is contained in:
parent
406f2de7ec
commit
6f0d6d747b
@ -5,7 +5,7 @@ import { IVaultData } from '@src/interfaces/IVaultData';
|
||||
|
||||
|
||||
export interface IPasswordVaultService {
|
||||
encryptData(plainData: IVaultData): IVaultData;
|
||||
encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData;
|
||||
decryptData(encryptedData: IVaultData): IVaultData;
|
||||
open(masterPW: string, encryptedMasterPW: string): boolean;
|
||||
isOpen(): boolean;
|
||||
@ -72,9 +72,15 @@ export class PasswordVaultService implements IPasswordVaultService {
|
||||
this.isVaultOpen = toBoolean(this.cache.get(this.encryptedInstanceId));
|
||||
let pwFromCache = this.cache.get(this.encryptedMasterPWInstanceId);
|
||||
this.encryptedMasterPw = isNullOrEmpty(pwFromCache) ? "" : pwFromCache;
|
||||
|
||||
if(!isNullOrEmpty(this.encryptedMasterPw)) {
|
||||
const plainPassword: string = this.decrypt(this.encryptedMasterPw, this.masterSecretKey);
|
||||
this.hashedMasterPw = CryptoJS.HmacSHA256(plainPassword, this.masterSecretKey).toString();
|
||||
}
|
||||
}
|
||||
|
||||
public encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData {
|
||||
|
||||
return {
|
||||
masterPW: this.hashedMasterPw,
|
||||
username: this.encryptUsername(plainData.username),
|
||||
|
@ -324,13 +324,15 @@ export default class PasswordVault extends SPFxAppDevWebPartComponent<PasswordVa
|
||||
<PrimaryButton disabled={this.state.isSaveButtonDisabled} onClick={() => {
|
||||
this.isNewVault = false;
|
||||
let encryptedMaster = this.currentMasterPW;
|
||||
|
||||
if(!this.enteredMasterPW.IsEmpty()) {
|
||||
encryptedMaster = this.props.passwordVaultService.setMasterPassword(this.enteredMasterPW);
|
||||
this.currentMasterPW = encryptedMaster;
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.encryptedData = this.props.passwordVaultService.encryptData({
|
||||
masterPW: encryptedMaster,
|
||||
note: this.editModeNote,
|
||||
password: this.editModePw,
|
||||
username: this.editModeUsername
|
||||
@ -435,12 +437,11 @@ export default class PasswordVault extends SPFxAppDevWebPartComponent<PasswordVa
|
||||
|
||||
if(isCorrectPW) {
|
||||
this.decryptedData = props.passwordVaultService.decryptData(this.encryptedData);
|
||||
this.editModeNote = this.decryptedData.note;
|
||||
this.editModePw = this.decryptedData.password;
|
||||
this.editModeUsername = this.decryptedData.username;
|
||||
}
|
||||
|
||||
this.editModeNote = this.decryptedData.note;
|
||||
this.editModePw = this.decryptedData.password;
|
||||
this.editModeUsername = this.decryptedData.username;
|
||||
|
||||
this.setState({
|
||||
isVaultOpen: isCorrectPW,
|
||||
showWrongMasterInfo: !isCorrectPW
|
||||
|
Loading…
x
Reference in New Issue
Block a user