Secure passcode
This commit is contained in:
parent
3245fca204
commit
3d65c592e8
|
@ -4,6 +4,8 @@ import RNUserDefaults from 'rn-user-defaults';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
|
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
|
||||||
import * as LocalAuthentication from 'expo-local-authentication';
|
import * as LocalAuthentication from 'expo-local-authentication';
|
||||||
|
import * as Haptics from 'expo-haptics';
|
||||||
|
import { sha256 } from 'js-sha256';
|
||||||
|
|
||||||
import Base from './Base';
|
import Base from './Base';
|
||||||
import Locked from './Locked';
|
import Locked from './Locked';
|
||||||
|
@ -63,18 +65,22 @@ const PasscodeEnter = ({ theme, finishProcess }) => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onEndProcess = (p) => {
|
const onEndProcess = (p) => {
|
||||||
if (p === passcode) {
|
setTimeout(() => {
|
||||||
finishProcess();
|
if (sha256(p) === passcode) {
|
||||||
} else {
|
finishProcess();
|
||||||
attempts += 1;
|
|
||||||
if (attempts >= MAX_ATTEMPTS) {
|
|
||||||
setStatus(TYPE.LOCKED);
|
|
||||||
setLockedUntil(new Date().toISOString());
|
|
||||||
} else {
|
} else {
|
||||||
ref.current.wrongPasscode();
|
attempts += 1;
|
||||||
setAttempts(attempts?.toString());
|
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) {
|
if (status === TYPE.LOCKED) {
|
||||||
|
|
|
@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
|
||||||
import { SafeAreaView } from 'react-navigation';
|
import { SafeAreaView } from 'react-navigation';
|
||||||
import RNUserDefaults from 'rn-user-defaults';
|
import RNUserDefaults from 'rn-user-defaults';
|
||||||
import Orientation from 'react-native-orientation-locker';
|
import Orientation from 'react-native-orientation-locker';
|
||||||
|
import { sha256 } from 'js-sha256';
|
||||||
|
|
||||||
// import I18n from '../i18n';
|
|
||||||
import { themedHeader } from '../utils/navigation';
|
import { themedHeader } from '../utils/navigation';
|
||||||
import { withTheme } from '../theme';
|
import { withTheme } from '../theme';
|
||||||
import { themes } from '../constants/colors';
|
import { themes } from '../constants/colors';
|
||||||
|
@ -16,7 +16,7 @@ import { PasscodeChoose } from '../containers/Passcode';
|
||||||
|
|
||||||
const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
|
const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
|
||||||
const savePasscode = async(passcode) => {
|
const savePasscode = async(passcode) => {
|
||||||
await RNUserDefaults.set(PASSCODE_KEY, passcode);
|
await RNUserDefaults.set(PASSCODE_KEY, sha256(passcode));
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue