1
0

functions.core.auth.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /* $Id: functions.core.auth.php 3052 2007-05-25 20:51:27Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * try to get Credentials
  17. *
  18. * @return array with credentials or false if no credentials found.
  19. */
  20. function getCredentials() {
  21. global $cfg;
  22. // check for basic-auth-supplied credentials (only if activated or there may
  23. // be wrong credentials fetched)
  24. if (($cfg['auth_type'] == 2) || ($cfg['auth_type'] == 3)) {
  25. if ((isset($_SERVER['PHP_AUTH_USER'])) && (isset($_SERVER['PHP_AUTH_PW']))) {
  26. $retVal = array();
  27. $retVal['username'] = strtolower($_SERVER['PHP_AUTH_USER']);
  28. $retVal['password'] = addslashes($_SERVER['PHP_AUTH_PW']);
  29. $retVal['md5pass'] = "";
  30. return $retVal;
  31. }
  32. }
  33. // check for http-post/get-supplied credentials (only if auth-type not 4)
  34. if ($cfg['auth_type'] != 4) {
  35. if (isset($_REQUEST['username'])) {
  36. if (isset($_REQUEST['md5pass'])) {
  37. $retVal = array();
  38. $retVal['username'] = strtolower($_REQUEST['username']);
  39. $retVal['password'] = "";
  40. $retVal['md5pass'] = $_REQUEST['md5pass'];
  41. return $retVal;
  42. } elseif (isset($_REQUEST['iamhim'])) {
  43. $retVal = array();
  44. $retVal['username'] = strtolower($_REQUEST['username']);
  45. $retVal['password'] = addslashes($_REQUEST['iamhim']);
  46. $retVal['md5pass'] = "";
  47. return $retVal;
  48. }
  49. }
  50. }
  51. // check for cookie-supplied credentials (only if activated)
  52. if ($cfg['auth_type'] == 1) {
  53. if (isset($_COOKIE["autologin"])) {
  54. $creds = explode('|', $_COOKIE["autologin"]);
  55. $retVal = array();
  56. $retVal['username'] = strtolower($creds[0]);
  57. $retVal['password'] = "";
  58. $retVal['md5pass'] = $creds[1];
  59. return $retVal;
  60. }
  61. }
  62. // no credentials found, return false
  63. return false;
  64. }
  65. /**
  66. * check if user authenticated
  67. *
  68. * @return int with :
  69. * 1 : user authenticated
  70. * 0 : user not authenticated
  71. */
  72. function isAuthenticated() {
  73. global $cfg, $db;
  74. // hold time
  75. $create_time = time();
  76. // user not set
  77. if (!isset($_SESSION['user']))
  78. return 0;
  79. // user changed password and needs to login again
  80. if ($_SESSION['user'] == md5($cfg["pagetitle"])) {
  81. // flush users cookie
  82. @setcookie("autologin", "", time() - 3600);
  83. // return
  84. return 0;
  85. }
  86. // user exists ?
  87. $recordset = $db->Execute("SELECT uid, hits FROM tf_users WHERE user_id=".$db->qstr($cfg["user"]));
  88. if ($recordset->RecordCount() != 1) {
  89. AuditAction($cfg["constants"]["access_denied"], "FAILED AUTH: ".$cfg["user"]);
  90. @session_destroy();
  91. return 0;
  92. }
  93. list($uid, $hits) = $recordset->FetchRow();
  94. // hold the uid in cfg-array
  95. $cfg["uid"] = $uid;
  96. // increment hit-counter
  97. $hits++;
  98. $db->Execute("UPDATE tf_users SET hits = ".$db->qstr($hits).", last_visit = ".$db->qstr($create_time)." WHERE uid = ".$db->qstr($uid));
  99. // return auth suc.
  100. return 1;
  101. }
  102. ?>