Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_setPinCode = async (pin, isReset) => {
const { intl, currentAccount, applicationPinCode } = this.props;
const { isExistUser, pinCode } = this.state;
const realmData = getUserDataWithUsername(currentAccount.name);
const userData = realmData[0];
// For exist users
if (isReset) {
await this._resetPinCode(pin);
return true;
}
if (isExistUser) {
if (!userData.accessToken && !userData.masterKey && applicationPinCode) {
const verifiedPin = decryptKey(applicationPinCode, Config.PIN_KEY);
if (verifiedPin === pin) {
await this._setFirstPinCode(pin);
} else {
Alert.alert(
intl.formatMessage({
id: 'alert.warning',
}),
intl.formatMessage({
id: 'alert.invalid_pincode',
}),
);
}
} else {
await this._verifyPinCode(pin);
}
return true;
_setDefaultPinCode = action => {
const { dispatch, username, currentAccount, pinCode } = this.props;
if (!action) {
const oldPinCode = decryptKey(pinCode, Config.PIN_KEY);
const pinData = {
pinCode: Config.DEFAULT_PIN,
username,
oldPinCode,
};
updatePinCode(pinData).then(response => {
const _currentAccount = currentAccount;
_currentAccount.local = response;
dispatch(updateCurrentAccount({ ..._currentAccount }));
const encryptedPin = encryptKey(Config.DEFAULT_PIN, Config.PIN_KEY);
dispatch(savePinCode(encryptedPin));
setPinCodeOpen(action);
dispatch(isPinCodeOpen(action));
_savePinCode = pin => {
const { dispatch } = this.props;
const encryptedPin = encryptKey(pin, Config.PIN_KEY);
dispatch(savePinCode(encryptedPin));
};
export const getDigitPinCode = pin => decryptKey(pin, Config.PIN_KEY);