mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
replace password with hash
This commit is contained in:
@@ -8,11 +8,12 @@ import game from "./game.js"
|
||||
import zone from "./zone_manager.js"
|
||||
import penaltyController from "./penalty_controller.js";
|
||||
import { playersBroadcast, sendUpdatedTeamInformations } from "./team_socket.js";
|
||||
import { sha256 } from "./util.js";
|
||||
|
||||
import { config } from "dotenv";
|
||||
config()
|
||||
|
||||
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
|
||||
const ADMIN_PASSWORD_HASH = process.env.ADMIN_PASSWORD_HASH;
|
||||
|
||||
/**
|
||||
* Send a message to all logged in admin sockets
|
||||
@@ -45,7 +46,8 @@ export function initAdminSocketHandler() {
|
||||
|
||||
//User is attempting to log in
|
||||
socket.on("login", (password) => {
|
||||
if (password === ADMIN_PASSWORD && !loggedIn) {
|
||||
const hash = sha256(password);
|
||||
if (hash === ADMIN_PASSWORD_HASH && !loggedIn) {
|
||||
//Attempt successful
|
||||
socket.emit("login_response", true);
|
||||
loggedInSockets.push(socket.id);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# template of the .env file
|
||||
```
|
||||
ADMIN_PASSWORD = 'admin password here'
|
||||
ADMIN_PASSWORD_HASH = 'admin password SHA256 hash here'
|
||||
HOST = 'traque.rezel.net'
|
||||
PORT = 3001
|
||||
SSL_KEY = "ssl/privkey.pem"
|
||||
SSL_CERT = "ssl/cert.pem"
|
||||
```
|
||||
# Run dev version
|
||||
First install the dependencies
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { createHash } from "crypto";
|
||||
|
||||
/**
|
||||
* Scale a value that is known to be in a range to a new range
|
||||
* for instance map(50,0,100,1000,2000) will return 1500 as 50 is halfway between 0 and 100 and 1500 is halfway through 1000 and 2000
|
||||
@@ -11,3 +13,7 @@
|
||||
export function map(value, oldMin, oldMax, newMin, newMax) {
|
||||
return ((value - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin;
|
||||
}
|
||||
|
||||
export function sha256(password) {
|
||||
return createHash('sha256').update(password).digest('hex');;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user