started with cookie implementation

This commit is contained in:
maru21 2023-10-03 19:05:06 +02:00
parent 1d711542da
commit 6d35d3d608

View File

@ -70,6 +70,7 @@ function setPassword() {
document.getElementById("login").style.display = "none"; document.getElementById("login").style.display = "none";
window.sessionStorage.setItem(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash)); window.sessionStorage.setItem(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash));
setCookie(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash.toString()), 10)
} }
} }
@ -79,45 +80,47 @@ export function getUsrId() {
} }
export function sessionVerification() { export function sessionVerification() {
let verfiedStatus = window.sessionStorage.getItem(sha256("verified"));
if (verfiedStatus == '') {verfiedStatus = null}
if (verfiedStatus != null) {
//user logged in
//write verifiedStatus content into passwordHash for decode check later //check if cookie exists
//passwordHash.set(XORCipher.decode(sha256("passwordHash"), verfiedStatus)); if (getCookie(sha256("verified")) != null) {
//document.getElementById("login").style.display = "none"; passwordHash.set(XORCipher.decode(sha256("passwordHash"), getCookie(sha256("verified"))));
//load NavigationBar with templates according to server window.sessionStorage.setItem(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash));
let data;
try {
data = window.sessionStorage.getItem(sha256(passwordHash.name));
} catch (e) {
verfiedStatus = null;
}
if (data === null) verfiedStatus = null;
let tF = retrieveData("templateFiles");
try {
tF = JSON.parse(tF);
} catch(e) {
verfiedStatus = null;
}
} else {
//check if cookie exists
if (getCookie(sha256("verified")) != null) {
//passwordHash.set(XORCipher.decode(sha256("passwordHash"), getCookie(sha256("verified"))));
//document.getElementById("login").style.display = "none";
//load NavigationBar with templates according to server
//initweb();
} else {
//document.getElementById("login").style.display = "block";
}
} }
if (verfiedStatus == null) window.stop(); let verfiedStatus = window.sessionStorage.getItem(sha256("verified"));
console.log('v: ',verfiedStatus); let data;
try {
data = window.sessionStorage.getItem(sha256(passwordHash.name));
} catch (e) {
verfiedStatus = null;
}
if (data === null) verfiedStatus = null;
//if (verfiedStatus != data) verfiedStatus = null
let vsString;
let pnString;
try {
vsString = XORCipher.decode(sha256("passwordHash"), verfiedStatus);
pnString = XORCipher.decode(passwordHash.name, data);
if (vsString != pnString) verfiedStatus = null;
} catch (e) {
verfiedStatus = null;
}
let tF = retrieveData("templateFiles");
try {
tF = JSON.parse(tF);
} catch(e) {
verfiedStatus = null;
}
if (verfiedStatus == null) {
console.log('v: ',verfiedStatus);
alert("Decryption failed; are you authenticated?");
window.location.reload();
return;
}
} }
const cyrb53 = (str, seed = 21) => { const cyrb53 = (str, seed = 21) => {