Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class database {
- public function register_gb($username, $password, $password2, $mail, $real_name, $game_tag, $salt, $location, $age_limit=0, $birthday=0, $birthmonth=0, $birthyear=0) {
- $username = addslashes($username);
- $password = $salt . addslashes($password);
- $password2 = $salt . addslashes($password2);
- $mail = addslashes($mail);
- $real_name = addslashes($real_name);
- $game_tag = addslashes($game_tag);
- $location = addslashes($location);
- $birthday_time = mktime(0, 0, 0, $birthmonth, $birthday, $birthyear);
- $age = date("Y") - $birthyear;
- $now = time();
- $check_username = mysql_num_rows(mysql_query("SELECT id FROM users WHERE username = '$username' LIMIT 1"));
- $check_email = mysql_num_rows(mysql_query("SELECT id FROM users WHERE mail = '$mail' LIMIT 1"));
- $max_users = $this->config("max_users", "int");
- $count_users = $this->count_db("users");
- 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.");
- if($age_limit != 0 && ($age < $age_limit)) die("Sorry, but you are not old enough to register.");
- if(!$username || !$password || !$password2 || !$mail || !$game_tag || !$location) die("Required information is missing.");
- if($check_username >= 1) die("The username is allready taken.");
- if($check_email >= 1) die("The email is allready used.");
- if($password != $password2) die("Passwords does not match.");
- if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $mail)) die("Invalid email.");
- foreach(hash_algos() as $hash) {
- $password = hash($hash, $password);
- $password2 = hash($hash, $password2);
- $act_hash = hash($hash, $username . $password . $salt . $mail . $location . $game_tag . $now . $real_name);
- }
- mysql_query("INSERT INTO `users` (`id`, `registerred`, `username`, `password`, `mail`, `game_tag`, `real_name`, `location`, `hash`, `active`)
- VALUES (NULL, '$now', '$username', '$password', '$mail', '$game_tag', '$real_name', '$location', '$act_hash', '0');");
- mysql_query("INSERT INTO `logged_in` (`id`, `time`) VALUES (NULL, '0');");
- /*
- * How to start the session when the login comes ;)
- session_start();
- $row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1"));
- $_SESSION = $row;
- */
- $message = "Hello,\nThank you for registerring at ".$this->config("site_name", "value").".\n\n
- Your activation code is: $act_hash\n\n
- You may click this link to activate your account: ".$this->config("activation_link", "value")."$act_hash&a=activate";
- $message = wordwrap($message, 70);
- mail($mail, $this->config("site_name", "value") . " activation mail", $message);
- echo "Thank you for registerring, you will receive an activation email soon.";
- } //end register();
- public function config($name, $value="value") {
- $qry = mysql_query("SELECT * FROM config WHERE name='$name' LIMIT 1");
- $row = mysql_fetch_array($qry);
- return $row[$value];
- } //end config();
- public function count_db($db) {
- $count = mysql_num_rows(mysql_query("SELECT * FROM $db"));
- return $count;
- } //end count_db();
- public function activate($code) {
- $chk = mysql_query("SELECT * FROM users WHERE hash='$code' LIMIT 1");
- $num = mysql_num_rows($chk);
- $row = mysql_fetch_array($chk);
- if($num <= 0) { echo "Couldn't find an account with that activation code.";
- } else {
- if($row["active"] == 1) { echo "This account has allready been activated.";
- } else {
- mysql_query("UPDATE users SET active = '1' WHERE hash='$code' LIMIT 1");
- echo "Your account has been activated, you may now login.";
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement