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";
window.sessionStorage.setItem(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash));
setCookie(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash.toString()), 10)
}
}
@ -79,16 +80,14 @@ export function getUsrId() {
}
export function sessionVerification() {
//check if cookie exists
if (getCookie(sha256("verified")) != null) {
passwordHash.set(XORCipher.decode(sha256("passwordHash"), getCookie(sha256("verified"))));
window.sessionStorage.setItem(sha256("verified"), XORCipher.encode(sha256("passwordHash"), passwordHash));
}
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
//passwordHash.set(XORCipher.decode(sha256("passwordHash"), verfiedStatus));
//document.getElementById("login").style.display = "none";
//load NavigationBar with templates according to server
let data;
try {
data = window.sessionStorage.getItem(sha256(passwordHash.name));
@ -97,6 +96,17 @@ export function sessionVerification() {
}
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);
@ -104,20 +114,13 @@ export function sessionVerification() {
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) {
console.log('v: ',verfiedStatus);
alert("Decryption failed; are you authenticated?");
window.location.reload();
return;
}
if (verfiedStatus == null) window.stop();
console.log('v: ',verfiedStatus);
}
const cyrb53 = (str, seed = 21) => {