aboutsummaryrefslogtreecommitdiffhomepage
path: root/public
diff options
context:
space:
mode:
authorMarvin Borner2019-01-27 18:04:38 +0100
committerMarvin Borner2019-01-27 18:04:38 +0100
commitdfce4c5a178275f4b7226ae397226cbbf84571a8 (patch)
tree267bb6e3275e92dc8b781229f8087996ed1df753 /public
parent46f92ac829cfaeb255317c99a0cb220e1ff6b071 (diff)
Added 3 retries
Diffstat (limited to 'public')
-rw-r--r--public/scripts/2_encryption.js11
-rw-r--r--public/scripts/4_input_pin.js10
-rw-r--r--public/scripts/chat.js14
3 files changed, 26 insertions, 9 deletions
diff --git a/public/scripts/2_encryption.js b/public/scripts/2_encryption.js
index a6f610e..7c7fb9b 100644
--- a/public/scripts/2_encryption.js
+++ b/public/scripts/2_encryption.js
@@ -10,7 +10,6 @@ let db;
*/
function setupDatabase() {
db = new Dexie('texx');
- window.db = db;
db.version(2).stores({
own_keys: '&key_type, key_data',
peer_keys: 'peer_id, key_data',
@@ -179,6 +178,15 @@ async function getPeerPublicKey(peerId) {
}
/**
+ * Resets the database/encryption
+ */
+function reset() {
+ db.delete();
+ localStorage.removeItem('database');
+ console.log('[LOG] Database has been deleted!')
+}
+
+/**
* Just a general test case
*/
function testEncryption() {
@@ -202,4 +210,5 @@ exports.decryptPrivate = decryptPrivateKey;
exports.check = isEncrypted;
exports.store = storePeerPublicKey;
exports.get = getPeerPublicKey;
+exports.reset = reset;
exports.test = testEncryption;
diff --git a/public/scripts/4_input_pin.js b/public/scripts/4_input_pin.js
index e0c96bd..b496e95 100644
--- a/public/scripts/4_input_pin.js
+++ b/public/scripts/4_input_pin.js
@@ -6,6 +6,8 @@ let pin = [];
* @param callback
*/
function init(callback) {
+ let tryCount = 0;
+
$('#1').focus().on('input', (el) => {
pin.push($(el.target).val());
$(el.target).val('*');
@@ -27,16 +29,16 @@ function init(callback) {
$('#4').on('input', (el) => {
pin.push($(el.target).val());
$(el.target).val('*');
- console.log(pin);
- callback(pin.join(''))
+ tryCount++;
+ callback(pin.join(''), tryCount)
});
}
/**
* Displays error message and clears input
*/
-function isWrong() {
- $('#pin_message').text('Passphrase is wrong!');
+function isWrong(message) {
+ $('#pin_message').text(message);
for (let i = 1; i < 5; i++) $(`#${i}`).val('');
$('#1').focus();
pin = [];
diff --git a/public/scripts/chat.js b/public/scripts/chat.js
index eb08c98..569e062 100644
--- a/public/scripts/chat.js
+++ b/public/scripts/chat.js
@@ -21,14 +21,20 @@ generator.initWithWordList(wordList);
peerId = await generator.generate().then(words => words.join('-'));
encryption.setup();
if (localStorage.getItem('database') === 'success' && await encryption.check()) {
- pinInput.init(async pin => {
+ pinInput.init(async (pin, tryCount) => {
try {
await encryption.decryptPrivate(await encryption.getPrivate(), pin);
chat()
} catch (e) {
- // TODO: 3 passphrase tries
- console.error('Passphrase is wrong!');
- pinInput.failure();
+ if (tryCount === 3) {
+ encryption.reset();
+ console.error('Too many tries!');
+ pinInput.failure('Account was deleted, this site will reload.');
+ setTimeout(() => location.reload(), 1500)
+ } else {
+ console.error('Passphrase is wrong!');
+ pinInput.failure('Passphrase is wrong!');
+ }
}
});
} else {