Skip to content
Snippets Groups Projects
Commit e532ab3f authored by Olgun Cengiz's avatar Olgun Cengiz :drum:
Browse files

Implemented identity blockage after failed pincode attempts

parent 2b9b13a2
No related branches found
No related tags found
1 merge request!17Resolve "System should block the login option for defined period of time, when user enter wrong local device PIN more than 3 attempts"
This commit is part of merge request !17. Comments created here will be created in the context of that merge request.
...@@ -544,17 +544,83 @@ function encryptMessage(message, password, label) { ...@@ -544,17 +544,83 @@ function encryptMessage(message, password, label) {
//********************************************************************************* //*********************************************************************************
function decryptMessage(message, password) { function decryptMessage(message, password) {
const secret = pvutils.stringToArrayBuffer(password); if (canTryPincode()) {
const buffer = decodePEM(message); const secret = pvutils.stringToArrayBuffer(password);
const buffer = decodePEM(message);
const asn1 = asn1js.fromBER(buffer);
const content = new pkijs.ContentInfo({schema: asn1.result}); const asn1 = asn1js.fromBER(buffer);
const enveloped = new pkijs.EnvelopedData({schema: content.content}); const content = new pkijs.ContentInfo({schema: asn1.result});
return enveloped.decrypt(0, {preDefinedData: secret}).then(result => { const enveloped = new pkijs.EnvelopedData({schema: content.content});
return pvutils.arrayBufferToString(result); return enveloped.decrypt(0, {preDefinedData: secret}).then(result => {
}).catch(() => { return pvutils.arrayBufferToString(result);
throw("Wrong pincode") }).catch(() => {
}) failPincodeAttempt(password);
});
} else {
return new Promise(function () {
const message = getTimeLeftInLocalStorage();
throw(message);
});
}
}
//*********************************************************************************
function getBlockFinishTimeInLocalStorage() {
return localStorage.getItem("blockFinishTime") ? localStorage.getItem("blockFinishTime") : getCurrentTime();
}
function getCurrentTime() {
return Math.floor(new Date().getTime() / 1000);
}
function getTimeLeftInLocalStorage() {
const blockFinishTime = getBlockFinishTimeInLocalStorage();
console.log("blockFinishTime:", blockFinishTime);
const timeNow = getCurrentTime();
const seconds = (blockFinishTime - timeNow) % 60;
let minutes = Math.floor((blockFinishTime - timeNow) / 60);
minutes %= 60;
const left = "Your identity has been blocked. Try again in " + minutes + " minutes and " + seconds + " seconds.";
return left;
}
function failPincodeAttempt(password) {
let message = "Wrong pincode";
if (password !== '00000000') {
let attempt = localStorage.getItem("attempt") || 1;
attempt = parseInt(attempt);
if (attempt === 9) {
var identitiesTemp = listIdentitiesFromLocalStorage();
for(var i in identitiesTemp) {
destroyIdentityFromLocalStorage(i)
}
message = "9 failed attempts. Identity is revoked!";
localStorage.removeItem("attempt");
console.log("identity is revoked!");
} else if (attempt % 3 === 0) {
const timeNow = getCurrentTime();
const blockFinishTime = timeNow + 10;
localStorage.setItem("blockFinishTime", blockFinishTime);
localStorage.setItem("attempt", attempt + 1);
message = "3 failed attempts. Identity is blocked!";
} else {
localStorage.setItem("attempt", attempt + 1);
}
console.log("Total Attempts:", attempt);
}
throw(message);
}
function canTryPincode() {
const timeNow = getCurrentTime();
const blockFinishTime = localStorage.getItem("blockFinishTime") || timeNow;
if (blockFinishTime <= timeNow) {
localStorage.removeItem("blockFinishTime");
return true;
} else {
return false;
}
} }
//********************************************************************************* //*********************************************************************************
...@@ -1190,6 +1256,7 @@ function getProfileData(identity) { ...@@ -1190,6 +1256,7 @@ function getProfileData(identity) {
executeRestfulFunction("private", viamApi, executeRestfulFunction("private", viamApi,
viamApi.identityGetIdentityProfileData).then(executeResult => { viamApi.identityGetIdentityProfileData).then(executeResult => {
if(executeResult.code === "200") { if(executeResult.code === "200") {
localStorage.removeItem("attempt");
console.log("In promise"); console.log("In promise");
console.log(executeResult); console.log(executeResult);
var listItem = {}; var listItem = {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment