When I ran the code below, it would usually add a number to testUses if there was a successful login. However, when I reloaded, you could still access home.html and the variable testUses still stayed 0 which meant that for some reason, it did not change. Should I put testUses outside the function? Please answer a fix or tip to change this.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<title>title</title>
<meta name="viewport" content="width=device-width">
<link href="stars.css" rel="stylesheet" type="text/css" />
<link href='https://fonts.googleapis.com/css?family=Quicksand' rel='stylesheet'>
<style>
.full {
width: 100%;
height: 100%;
top: 0px;
left: 0px;
position: absolute;
overflow: hidden;
}
.center {
left: 50%;
top:50%;
transform: translate(-50%, -50%);
position: absolute;
}
</style>
</head>
<body style='overflow:hidden;padding:0px;visibilty:hidden'>
<div class='full'>
<div class='center' style='width:300px;padding:2px'>
<div class="main"></div>
<script>
if ( window.location !== window.parent.location ) {
} else {
}
</script>
<input type= password id="access" placeholder="Access Key" onchange="access()"><br>
<script>
function access() {
var input =
document.getElementById("access").value;
var testUses = 0;
const testHash = "cyrb53('a') -> 5204429218075600"
const adminHash = "cyrb53('a') -> 4413594719508086";
const cyrb53 = (str, seed = 0) => {
let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};
var inputHash = (`cyrb53('a') -> ${cyrb53(input)}`);
function home() {
document.write('<iframe src="home.html" height="100%" width="100%"></iframe>');
}
if (inputHash == adminHash) {
home();
} else if (inputHash == testHash && testUses <= 1) {
home();
testUses += 1;
} else {
document.getElementById('access').value = '';
}
}
</script>
</div>
</body>
</html>
>Solution :
You can store testUses in localStorage.
let testUses = +localStorage.getItem('testUses') || 0;
// update value:
testUses++;
localStorage.setItem('testUses', testUses);