Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

  /**
   *By Red3v0lution
   *Object-Oriented Content Management System
   *PHP 5.2.9-1 && MySQL Database 5.1.32
   *April 21, 2009
   **/

  /**
  Usage:
  ___________________________________________________________________
  |new register($username, $password, $register);                                  |
  |_________________________________________________________________|
  |The users credentials will be stored in the database if the      |
  |username is free.                                                |
  |_________________________________________________________________|
     **/

class register
{
  //User variables
  private $username;
  private $password;
  private $email;

  //Storage variable
  private $return;

  //Class Methods
  private function checkLogin()
  {
    if ($_SESSION['logged_in'] == 1)
    {
      if ($_SESSION['user_agent'] != $_SERVER['HTTP_USER_AGENT'])
      {
        $this->return = "You trying to hijack someone's session? This session is destroyed.";
        $_SESSION = array();
        session_destroy();
        return 0;
      }
      else
      {
      $this->return = "You already have an account.";
      return 0;
      }
    }
    else
    {
      return 1;
    }
  }

  private function clean()
  {
    $this->username = trim($this->username);
    $this->password = md5($this->password);
    $this->email = trim($this->email);
    return 1;
  }

  private function IsUsernameFree()
  {
    $result = mysql_query("SELECT uid FROM users WHERE username = '$this->username' LIMIT 1;");
    if ($row = mysql_fetch_assoc($result))
    {
      $this->return = "Sorry, but $this->username has already been taken. Please choose another one.";
      return 0;
    }
    else
    {
      return 1;
    }
  }

  private function create()
  {
    mysql_query("INSERT INTO users (username, password, email, access) VALUES ($this->username, $this->password, $this->email, 1);") OR die('Could not enter information into database. The administrator has been notified, so it should be working again soon.');
  }

  public function __construct($username, $password, $email)
  {
    $this->username = $username;
    $this->password = $password;
    $this->email = $email;

    checkLogin() OR die($this->return);

    require_once 'connect.php';

    $this->clean() OR die('Supplied input could not be cleaned.');
    if($this->IsUsernameFree())
    {
      $this->create();
    }
    else
    {
      die($this->return);
    }
  }  
}  

?>