Guest User

php timestamp based authentication

a guest
Apr 2nd, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2.  
  3.     const salt = "such_salt";
  4.     const timeframe = 10;
  5.  
  6.     function gen()
  7.     {
  8.         return strtoupper(substr(md5(salt.time()),0,12));
  9.     }
  10.  
  11.     function auth()
  12.     {
  13.         $valid = false;
  14.        
  15.         if (timeframe<1)
  16.         {
  17.             $len_t = 1;
  18.         }
  19.         else
  20.         {
  21.             $len_t = round(timeframe);
  22.         }
  23.  
  24.         if (isset($_GET['pass']))
  25.         {
  26.  
  27.             $t = time();
  28.  
  29.             for ($i=0; $i<$len_t; $i++)
  30.             {
  31.                 if (strtoupper(substr(md5(salt.($t-$i)),0,12)) == $_GET['pass'] )
  32.                 {
  33.                     $valid = true;
  34.                     break;
  35.                 }
  36.             }
  37.        
  38.         }
  39.        
  40.         return $valid;
  41.     }
  42.    
  43.     echo "<pre>";
  44.    
  45.     echo "<a href=\"?pass=".gen()."\">auth</a><p>";
  46.    
  47.     var_dump(auth());
  48.    
  49.     echo "</pre>";
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment