Anonymous 3D Imageboard http://cyberia.digital/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5KB

  1. <?php
  2. session_start();
  3. require_once "Utils/Constants.php";
  4. require_once 'Utils/Helpers.php';
  5. Class AdminController {
  6. function validPassword($password){
  7. $passwordFile = file_get_contents(Constants::CONST_PASSWORD_FOLDER."/".Constants::CONST_PASSWORD_FILE, FILE_USE_INCLUDE_PATH);
  8. if( Helpers::verify_pw($password, $passwordFile)){
  9. $_SESSION['superadmin'] = true;
  10. return true;
  11. } else {
  12. $_SESSION['superadmin'] = false;
  13. return false;
  14. }
  15. }
  16. function unlog(){
  17. $_SESSION['superadmin'] = false;
  18. return true;
  19. }
  20. function isAdminLogged(){
  21. if(!isset( $_SESSION['superadmin'])) return false;
  22. return $_SESSION['superadmin'];
  23. }
  24. function setPassword($password){
  25. if($this->isPassword()) return false;
  26. $hash = Helpers::hash_pw($password);
  27. //Test if the folder exist
  28. if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/')) {
  29. mkdir(Constants::CONST_PASSWORD_FOLDER, 0777, true);
  30. }
  31. //Record the hash
  32. $fp = fopen(Constants::CONST_PASSWORD_FOLDER."/".Constants::CONST_PASSWORD_FILE, 'w');
  33. fwrite($fp, $hash);
  34. fclose($fp);
  35. return true;
  36. }
  37. function isPassword(){
  38. if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/')) return false;
  39. if (!file_exists(Constants::CONST_PASSWORD_FOLDER.'/'.Constants::CONST_PASSWORD_FILE)) return false;
  40. return true;
  41. }
  42. }