Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.82 KB | None | 0 0
  1. <?php
  2.  
  3. class database {
  4.    
  5.     public function register_gb($username, $password, $password2, $mail, $real_name, $game_tag, $salt, $location, $age_limit=0, $birthday=0, $birthmonth=0, $birthyear=0) {
  6.        
  7.         $username = addslashes($username);
  8.         $password = $salt . addslashes($password);
  9.         $password2 = $salt . addslashes($password2);
  10.         $mail = addslashes($mail);
  11.         $real_name = addslashes($real_name);
  12.         $game_tag = addslashes($game_tag);
  13.         $location = addslashes($location);
  14.        
  15.         $birthday_time = mktime(0, 0, 0, $birthmonth, $birthday, $birthyear);
  16.         $age = date("Y") - $birthyear;
  17.         $now = time();
  18.        
  19.         $check_username = mysql_num_rows(mysql_query("SELECT id FROM users WHERE username = '$username' LIMIT 1"));
  20.         $check_email = mysql_num_rows(mysql_query("SELECT id FROM users WHERE mail = '$mail' LIMIT 1"));
  21.        
  22.         $max_users = $this->config("max_users", "int");
  23.         $count_users = $this->count_db("users");
  24.        
  25.         if($max_users != 0 && ($max_users <= $count_users)) die("Sorry, but we've reached the max ammount of users in our database, please check again later as we will increase this value.");
  26.         if($age_limit != 0 && ($age < $age_limit)) die("Sorry, but you are not old enough to register.");
  27.         if(!$username || !$password || !$password2 || !$mail || !$game_tag || !$location) die("Required information is missing.");
  28.         if($check_username >= 1) die("The username is allready taken.");
  29.         if($check_email >= 1) die("The email is allready used.");
  30.         if($password != $password2) die("Passwords does not match.");
  31.         if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $mail)) die("Invalid email.");
  32.        
  33.             foreach(hash_algos() as $hash) {
  34.                 $password = hash($hash, $password);
  35.                 $password2 = hash($hash, $password2);
  36.                 $act_hash = hash($hash, $username . $password . $salt . $mail . $location . $game_tag . $now . $real_name);
  37.             }
  38.            
  39.         mysql_query("INSERT INTO `users` (`id`, `registerred`, `username`, `password`, `mail`, `game_tag`, `real_name`, `location`, `hash`, `active`)
  40.         VALUES (NULL, '$now', '$username', '$password', '$mail', '$game_tag', '$real_name', '$location', '$act_hash', '0');");
  41.         mysql_query("INSERT INTO `logged_in` (`id`, `time`) VALUES (NULL, '0');");
  42.        
  43.         /*
  44.          * How to start the session when the login comes ;)
  45.        
  46.         session_start();
  47.        
  48.         $row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1"));
  49.         $_SESSION = $row;
  50.        
  51.         */
  52.        
  53.             $message = "Hello,\nThank you for registerring at ".$this->config("site_name", "value").".\n\n
  54.                         Your activation code is: $act_hash\n\n
  55.                         You may click this link to activate your account: ".$this->config("activation_link", "value")."$act_hash&a=activate";
  56.             $message = wordwrap($message, 70);
  57.             mail($mail, $this->config("site_name", "value") . " activation mail", $message);
  58.        
  59.         echo "Thank you for registerring, you will receive an activation email soon.";
  60.        
  61.     } //end register();
  62.    
  63.     public function config($name, $value="value") {
  64.    
  65.         $qry = mysql_query("SELECT * FROM config WHERE name='$name' LIMIT 1");
  66.         $row = mysql_fetch_array($qry);
  67.        
  68.         return $row[$value];
  69.        
  70.     } //end config();
  71.    
  72.     public function count_db($db) {
  73.    
  74.         $count = mysql_num_rows(mysql_query("SELECT * FROM $db"));
  75.        
  76.         return $count;
  77.        
  78.     } //end count_db();
  79.    
  80.     public function activate($code) {
  81.         $chk = mysql_query("SELECT * FROM users WHERE hash='$code' LIMIT 1");
  82.         $num = mysql_num_rows($chk);
  83.         $row = mysql_fetch_array($chk);
  84.        
  85.         if($num <= 0) { echo "Couldn't find an account with that activation code.";
  86.         } else {
  87.             if($row["active"] == 1) { echo "This account has allready been activated.";
  88.             } else {
  89.                 mysql_query("UPDATE users SET active = '1' WHERE hash='$code' LIMIT 1");
  90.                 echo "Your account has been activated, you may now login.";
  91.             }
  92.         }
  93.     }
  94.  
  95. }
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement