Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. /* in site config */
  2. $Config['siteSalt'] = 'ksjh2k234jk45kj4uo8vxoise8';
  3.  
  4. function hashSteamId($steamId){
  5.   global $Config;
  6.   return sha1($steamId . $Config['siteSalt']);
  7. }
  8.  
  9.  
  10. /* login.php */
  11. if(isset($_GET['openid_claimed_id'])){
  12.   $steamId = SteamSignIn::validate();
  13.   //if successful login
  14.   if($steamId){
  15.     $hash = hashSteamId($steamId);
  16.     $cookieData = $steamId.'|'.$hash;
  17.     setcookie('user', $cookieData, time()+60*60*24*365); //sets the cookie for a year
  18.     echo 'Successfully logged in';
  19.     exit;
  20.   }
  21.   echo 'Failed to validate login';
  22.   exit;
  23. }
  24.  
  25. echo '<a href="'.SteamSignIn::genUrl().'">login</a>';
  26.  
  27.  
  28. /* on each page load */
  29. //tries to load the logged in user. format should be 'steamId|hash'
  30. $userCookieData = filter_input(INPUT_COOKIE, 'user', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR);
  31. if($userCookieData){
  32.   //loads the steam id (all data before the "|")
  33.   $userSteamId = strtok($userCookieData, '|');
  34.   //loads the hash (the rest of the str in $userCookieData)
  35.   $userSteamHash = strtok('');
  36.  
  37.   //checks the hash supplied against what it should be
  38.   if($userSteamHash === hashSteamId($userSteamId)){
  39.     //is valid login. do stuff
  40.   }
  41. }
  42.  
  43.  
  44. /* logout.php */
  45. //deletes the cookie
  46. setcookie('userId', 0, time()-60*60*24*30);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement