Add password setting and check password before deleting it
This commit is contained in:
@@ -5,7 +5,7 @@ import { AppText } from './app-text'
|
||||
import { hasEncryptionObservable } from '../local-storage'
|
||||
import styles from '../styles'
|
||||
import { passwordPrompt } from './labels'
|
||||
import { openDbConnection, requestHash, deleteDbAndOpenNew } from '../db'
|
||||
import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db'
|
||||
import App from './app'
|
||||
|
||||
export default class PasswordPrompt extends Component {
|
||||
@@ -21,35 +21,27 @@ export default class PasswordPrompt extends Component {
|
||||
}
|
||||
})
|
||||
|
||||
this.tryToOpenDb = async (msg) => {
|
||||
msg = JSON.parse(msg)
|
||||
if (msg.type === 'sha512') {
|
||||
const hash = msg.message
|
||||
const key = new Uint8Array(64)
|
||||
for (let i = 0; i < key.length; i++) {
|
||||
const twoDigitHex = hash.slice(i * 2, i * 2 + 2)
|
||||
key[i] = parseInt(twoDigitHex, 16)
|
||||
}
|
||||
try {
|
||||
await openDbConnection(key)
|
||||
this.setState({showApp: true})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
this.setState({ wrongPassword: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nodejs.start('main.js')
|
||||
nodejs.channel.addListener(
|
||||
'message',
|
||||
this.tryToOpenDb,
|
||||
this.passHashToDb,
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
passHashToDb = async msg => {
|
||||
msg = JSON.parse(msg)
|
||||
if (msg.type != 'sha512') return
|
||||
try {
|
||||
await openDb({hash: msg.message, persistConnection: true })
|
||||
this.setState({ showApp: true })
|
||||
} catch (err) {
|
||||
this.setState({ wrongPassword: true })
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
nodejs.channel.removeListener('message', this.tryToOpenDb)
|
||||
nodejs.channel.removeListener('message', this.passHashToDb)
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -71,7 +63,7 @@ export default class PasswordPrompt extends Component {
|
||||
/>
|
||||
<TouchableOpacity
|
||||
style={styles.settingsButton}
|
||||
onPress={async () => {
|
||||
onPress={() => {
|
||||
requestHash(this.state.password)
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user