<?php

function getPermission() {
  $canedit = false;
  $cookiehash = md5('http://addingajax.com/tmp'); 
  define('COOKIEHASH', $cookiehash);

  if ( !defined('USER_COOKIE') )
        define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
  if ( !defined('PASS_COOKIE') )
        define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);

  if (isset($_COOKIE[USER_COOKIE])) {
       $user =  $_COOKIE[USER_COOKIE];
  }

  if (isset($_COOKIE[PASS_COOKIE])) {
      $pass = $_COOKIE[PASS_COOKIE];
  }

  $conn = mysql_connect('localhost','nazwa_uzytkownika','haslo');
  mysql_select_db('baza_danych');

  if ($user && $pass) {
     $result = mysql_query("select ID, user_login, user_pass from wp_users where user_login = '$user'");

     if($result) {
       while($row = mysql_fetch_row($result)) {

         if ($pass == md5($row[2])) {
            $canedit = true;
         } 
       }
     }
  mysql_close($conn);
  return $canedit;
  }
}

?>
