Secure passcode

This commit is contained in:
Diego Mello 2020-04-27 15:19:45 -03:00
parent 3245fca204
commit 3d65c592e8
2 changed files with 18 additions and 12 deletions

View File

@ -4,6 +4,8 @@ import RNUserDefaults from 'rn-user-defaults';
import PropTypes from 'prop-types';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
import * as LocalAuthentication from 'expo-local-authentication';
import * as Haptics from 'expo-haptics';
import { sha256 } from 'js-sha256';
import Base from './Base';
import Locked from './Locked';
@ -63,18 +65,22 @@ const PasscodeEnter = ({ theme, finishProcess }) => {
}, []);
const onEndProcess = (p) => {
if (p === passcode) {
setTimeout(() => {
if (sha256(p) === passcode) {
finishProcess();
} else {
attempts += 1;
if (attempts >= MAX_ATTEMPTS) {
setStatus(TYPE.LOCKED);
setLockedUntil(new Date().toISOString());
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
} else {
ref.current.wrongPasscode();
setAttempts(attempts?.toString());
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Warning);
}
}
}, 200);
};
if (status === TYPE.LOCKED) {

View File

@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import { SafeAreaView } from 'react-navigation';
import RNUserDefaults from 'rn-user-defaults';
import Orientation from 'react-native-orientation-locker';
import { sha256 } from 'js-sha256';
// import I18n from '../i18n';
import { themedHeader } from '../utils/navigation';
import { withTheme } from '../theme';
import { themes } from '../constants/colors';
@ -16,7 +16,7 @@ import { PasscodeChoose } from '../containers/Passcode';
const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
const savePasscode = async(passcode) => {
await RNUserDefaults.set(PASSCODE_KEY, passcode);
await RNUserDefaults.set(PASSCODE_KEY, sha256(passcode));
navigation.pop();
};