-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from luca-ceri/dev
Pull Request For Autentication (V1.3.0)
- Loading branch information
Showing
18 changed files
with
587 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
data.json | ||
changes.log | ||
data.json | ||
test.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<!DOCTYPE html> | ||
<html lang="it"> | ||
<head> | ||
<title>Authentication management</title> | ||
<input type="hidden" value="0" id="passwd"> | ||
<script> | ||
const digest = async ({ algorithm = "SHA-256", message }) => | ||
Array.prototype.map | ||
.call( | ||
new Uint8Array( | ||
await crypto.subtle.digest(algorithm, new TextEncoder().encode(message)) | ||
), | ||
(x) => ("0" + x.toString(16)).slice(-2) | ||
) | ||
.join(""); | ||
digest({message: prompt("Enter Password:")}) | ||
.then(ins=>{ | ||
fetch("./passwd.json",{cache: "no-cache"}) | ||
.then(response => response.json()) | ||
.then(obj=>{ | ||
if(obj.includes(ins)){ | ||
document.getElementById('passwd').value=ins; | ||
}else{ | ||
if(confirm("Password incorrect\nTry Again?")) | ||
window.location.replace("./auth.html"); | ||
else | ||
window.location.replace("./index.html"); | ||
} | ||
}) | ||
}) | ||
function copyToken() { | ||
let token = document.getElementById("token").value; | ||
navigator.clipboard.writeText(token); | ||
} | ||
</script> | ||
<link rel="stylesheet" href="style.css"> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="./style_auth.css" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@800&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet"> | ||
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@2/dist/zero-md.min.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<ul class="header ul-navbar"> | ||
<li id="title" class="li-navbar">Baseball Scoreboard</li> | ||
<li class="li-navbar"><a href="./index.html" class="link a-navbar">Home</a></li> | ||
<li class="li-navbar"><a href="./admin.html" class="link a-navbar">Admin</a></li> | ||
<li class="li-navbar"><a href="./auth.html" class="link active a-navbar">Auth</a></li> | ||
<li class="li-navbar"><a href="./scoreboard.html" class="link a-navbar" target="_blank">Scoreboard <span class="material-icons" style="font-size: 18px;">open_in_new</span></a></li> | ||
<li class="li-navbar"><a href="./pregame.html" class="link a-navbar" target="_blank">Pre game <span class="material-icons" style="font-size: 18px;">open_in_new</span></a></li> | ||
<li class="li-navbar"><a href="./postgame.html" class="link a-navbar" target="_blank">Post game <span class="material-icons" style="font-size: 18px;">open_in_new</span></a></li> | ||
<li class="li-navbar"><a href="./parz.html" class="link a-navbar" target="_blank">Partials <span class="material-icons" style="font-size: 18px;">open_in_new</span></a></li> | ||
</ul> | ||
</div> | ||
<div class="div-psw"> | ||
<h1>Change Password</h1> | ||
<form class="form-psw" method="dialog"> | ||
<label for="oldpsw">Old password:</label> | ||
<input type="password" id="oldpsw" name="oldpsw" required> | ||
<label for="newpsw">New password:</label> | ||
<input type="password" id="newpsw" name="newpsw" required> | ||
<label for="repeatpsw">Repeat new password:</label> | ||
<input type="password" id="repeatpsw" name="repeatpsw" required> | ||
<p>Select an option:</p> | ||
<span> | ||
<input type="radio" id="opt1" name="opt" value="add" required> | ||
<label for="opt1">Add password</label> | ||
</span> | ||
<span> | ||
<input type="radio" id="opt2" name="opt" value="replace" required> | ||
<label for="opt2">Replace</label> | ||
</span> | ||
<input type="submit" value="Invia" style="margin: 10px 0px 10px;" onclick="update()"> | ||
</form> | ||
</div> | ||
<div class="div-token"> | ||
<h1>Generate Token</h1> | ||
<div style="display: flex;"> | ||
<input type="text" id="token" name="token" readonly> | ||
<button id="copy" onclick="copyToken()" class="material-icons-outlined"> | ||
file_copy | ||
</button> | ||
</div> | ||
<button style="margin: 10px" onclick="update2()">Generate Token</button> | ||
</div> | ||
</body> | ||
<script src="./auth.js"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
function update(){ | ||
const digest = async ({ algorithm = "SHA-256", message }) => | ||
Array.prototype.map | ||
.call( | ||
new Uint8Array( | ||
await crypto.subtle.digest(algorithm, new TextEncoder().encode(message)) | ||
), | ||
(x) => ("0" + x.toString(16)).slice(-2) | ||
) | ||
.join(""); | ||
|
||
old=document.getElementById("oldpsw").value; | ||
new_p=document.getElementById("newpsw").value; | ||
rep_pass=document.getElementById("repeatpsw").value; | ||
|
||
if(new_p!=rep_pass){ | ||
alert("The New password are different") | ||
return; | ||
} | ||
if(document.getElementById("opt1").checked) | ||
opt="add"; | ||
else if(document.getElementById("opt2").checked) | ||
opt="sub"; | ||
else | ||
return; | ||
digest({message: new_p}) | ||
.then(ins=>{ | ||
new_p=ins; | ||
digest({message: old}) | ||
.then(ins2=>{ | ||
old=ins2; | ||
submit(new_p,old,opt); | ||
}) | ||
}) | ||
} | ||
function submit(new_p,old,opt){ | ||
ndata="old="+old+"&new="+new_p+"&ope="+opt; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("POST", './update_pass.php', true); | ||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | ||
xhr.onreadystatechange = function() { // Call a function when the state changes. | ||
if (this.readyState === XMLHttpRequest.DONE && this.status != 200) { | ||
window.alert("An error occurred while updating password\nSee console for more information\nERROR code: "+this.status); | ||
console.debug("Error while sending request\nCODE:"+this.status+"\nRECIVED: '"+this.response+"'"); | ||
|
||
}else{ | ||
if(opt="sub"&&this.status==200&&this.readyState === XMLHttpRequest.DONE) | ||
window.location.replace("./auth.html"); | ||
} | ||
} | ||
xhr.send(ndata); | ||
} | ||
function update2(){ | ||
const digest = async ({ algorithm = "SHA-256", message }) => | ||
Array.prototype.map | ||
.call( | ||
new Uint8Array( | ||
await crypto.subtle.digest(algorithm, new TextEncoder().encode(message)) | ||
), | ||
(x) => ("0" + x.toString(16)).slice(-2) | ||
) | ||
.join(""); | ||
|
||
old=document.getElementById("passwd").value; | ||
new_t=Math.random().toString(16).substr(2, 8);; | ||
|
||
opt="sub"; | ||
digest({message: new_t}) | ||
.then(ins=>{ | ||
new_t=ins; | ||
if(submit2(new_t,old,opt)) | ||
document.getElementById("token").value=new_t; | ||
}) | ||
} | ||
|
||
function submit2(new_p,old,opt){ | ||
ndata="old="+old+"&new="+new_p+"&ope="+opt; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("POST", './update_token.php', true); | ||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | ||
xhr.onreadystatechange = function() { // Call a function when the state changes. | ||
if (this.readyState === XMLHttpRequest.DONE && this.status != 200) { | ||
window.alert("An error occurred while updating score\nSee console for more information\nERROR code: "+this.status); | ||
console.debug("Error while sending request\nCODE:"+this.status+"\nRECIVED: '"+this.response+"'"); | ||
|
||
} | ||
} | ||
xhr.send(ndata); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<body> | ||
<h1>The password is incorrect</h1> | ||
<p>click <a href="./admin_obs.html">here</a> to try again</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"a01edad91c00abe7be5b72b5e36bf4ce3c6f26e8bce3340eba365642813ab8b6" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.