DatabaseAuthenticator.inc 716 B

1234567891011121314151617181920212223242526
  1. <?php
  2. class DatabaseAuthenticator {
  3. public function authenticate($username, $password) {
  4. $session = new Session();
  5. $session->clear();
  6. $logger = new Logger();
  7. try {
  8. $database = new Database();
  9. $sql = sprintf("SELECT users_auth.user_id FROM users_auth JOIN users on users.user_id = users_auth.user_id WHERE username = '%s' AND passwordhash = '%s'"
  10. , $username
  11. , sha1($password)
  12. );
  13. $response = $database->query($sql);
  14. if ($response != array()) {
  15. $userId = $response[0]['user_id'];
  16. $session->setValue("logged_in", $userId);
  17. return $userId;
  18. }
  19. } catch (DatabaseConnectionException $e) {
  20. $logger->error("Unable to communicate with database");
  21. }
  22. return false;
  23. }
  24. }