1
0
mirror of https://github.com/AlexKrunch/AnonIB-3D.git synced 2024-11-25 20:48:30 -05:00
AnonIB-3D/ready2use/srv/php/AdminController.php

60 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2019-08-17 04:21:07 -04:00
<?php
session_start();
require_once "Utils/Constants.php";
require_once 'Utils/Helpers.php';
Class AdminController {
function validPassword($password){
$passwordFile = file_get_contents(Constants::CONST_PASSWORD_FOLDER."/".Constants::CONST_PASSWORD_FILE, FILE_USE_INCLUDE_PATH);
if( Helpers::verify_pw($password, $passwordFile)){
$_SESSION['superadmin'] = true;
return true;
} else {
$_SESSION['superadmin'] = false;
return false;
}
}
function unlog(){
$_SESSION['superadmin'] = false;
return true;
}
function isAdminLogged(){
if(!isset( $_SESSION['superadmin'])) return false;
return $_SESSION['superadmin'];
}
function setPassword($password){
if($this->isPassword()) return false;
$hash = Helpers::hash_pw($password);
//Test if the folder exist
if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/')) {
mkdir(Constants::CONST_PASSWORD_FOLDER, 0777, true);
}
//Record the hash
$fp = fopen(Constants::CONST_PASSWORD_FOLDER."/".Constants::CONST_PASSWORD_FILE, 'w');
fwrite($fp, $hash);
fclose($fp);
return true;
}
function isPassword(){
if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/')) return false;
if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/'.Constants::CONST_PASSWORD_FILE)) return false;
return true;
}
}