Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ************************* config.php *********************************
- $config['DB_NAME_FORUM'] = "cpg_db";
- $config['DB_USER_TABLE'] = "wcf1_user";
- $config['DB_RANK_TABLE'] = "wcf1_user_rank";
- $config['ADMIN_RANK'] = array("Admin","Headadmin","Super Moderator");
- $config['MOD_RANK'] = array("Moderator");
- ************************* user.php ***********************************
- class User {
- public $userID;
- public $name;
- public $password;
- public $hash;
- public $valid;
- public $admin;
- public function User(){
- $this->valid = false;
- }
- public function login($user, $pass){
- global $db, $config;
- $result = $db->query_first("SELECT userID, username, password, salt FROM ".$config['DB_NAME_FORUM'].".".$config['DB_USER_TABLE']." WHERE username = '".$db->escape($user)."' AND banned = 0");
- if(empty($result['username'])){
- $this->valid = false;
- return $this->valid;
- }
- $hash = $this->getHash($pass,$result['salt']);
- if($hash == $result['password']){
- $this->userID = $result['userID'];
- $this->name = $result['username'];
- $this->password = $pass;
- $this->hash = $result['password'];
- $this->valid = true;
- $rank_query = $db->query_first("SELECT r.rankTitle as rank
- FROM ".$config['DB_NAME_FORUM'].".".$config['DB_USER_TABLE']." u, ".$config['DB_NAME_FORUM'].".".$config['DB_RANK_TABLE']." r
- WHERE u.username = '".$db->escape($user)."' AND u.rankID = r.rankID");
- $this->admin = (array_search($rank_query['rank'], $config['MOD_RANK'])>-1) ? 1 : 0;
- $this->admin = (array_search($rank_query['rank'], $config['ADMIN_RANK'])>-1) ? 2 : $this->admin;
- }else{
- $this->valid = false;
- }
- return $this->valid;
- }
- private function getHash($password, $salt){
- return sha1($salt.sha1($salt.sha1($password)));
- }
- public function loadSession(){
- if(empty($_SESSION['login_username']) || empty($_SESSION['login_password'])){
- return false;
- }
- return $this->login($_SESSION['login_username'],$_SESSION['login_password']);
- }
- public function saveSession(){
- if($this->valid === true){
- $_SESSION['login_username'] = $this->name;
- $_SESSION['login_password'] = $this->password;
- }
- }
- public function logout(){
- unset($_SESSION['login_username']);
- unset($_SESSION['login_password']);
- $this->valid=false;
- $this->admin=0;
- $this->name = null;
- $this->password = null;
- $this->hash = null;
- $this->userID = null;
- }
- }
Add Comment
Please, Sign In to add comment