Advertisement
Guest User

PHP

a guest
Apr 26th, 2017
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.53 KB | None | 0 0
  1. <?php
  2.  
  3. Class Users {
  4.  
  5.     public function habbocTicket() {
  6.     global $db;
  7.     $str=  '0123456789abcdefghijklmnopqrstuvwxyz';
  8.         $shuffled = str_shuffle($str);
  9.  
  10.  
  11.      $ticket =  SNAME . 'Auth--'  . $shuffled . '--Ticket';
  12.  
  13.      $db->save('UPDATE users SET auth_ticket =:auth_ticket WHERE username=:username LIMIT 1',
  14.  
  15.         array(
  16.             'auth_ticket'   =>  $ticket,
  17.             'username'    =>    $this->userData()->username
  18.         ));
  19.      return $ticket;
  20.     }
  21.  
  22.     public function passHash($var) {
  23.  
  24.         $str = 'abcdefghijklmnopqrstuvwxyz'
  25.  
  26.             . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  27.  
  28.             . '0123456789!@#$%^&*()';
  29.  
  30.         $shuffled = str_shuffle($str);
  31.  
  32.         return sha1($var . md5($var . $str)) . sha1($var . $str);
  33.  
  34.     }
  35.  
  36.     public function checkUsername($user) {
  37.         global $db;
  38.         $req = $db->row('SELECT * FROM users WHERE username=:username LIMIT 1', array('username' => $user));
  39.         return $req;
  40.     }
  41.  
  42.     public function checkEmail($email) {
  43.         global $db;
  44.         $req = $db->row('SELECT * FROM users WHERE mail=:mail LIMIT 1', array('mail' => $email));
  45.         return $req;
  46.     }
  47.     public function findAccount($user, $pass)  {
  48.         global $db;
  49.         $result = $db->row('SELECT * FROM users WHERE username=:username AND password=:password LIMIT 1',
  50.             array(
  51.             'username'      =>      $user,
  52.             'password'      =>      $this->passHash($pass)
  53.         ));
  54.  
  55.         return $result;
  56.     }
  57.  
  58.     public function Login() {
  59.         global $db, $core;
  60.         if(isset($_POST['username']) && $_GET['action'] == "login")  {
  61.  
  62.             if(!empty($_POST['username']) && !empty($_POST['password'])) {
  63.                 $userdata = $db->query('SELECT id, username, password FROM users WHERE username=:username AND password =:password',
  64.                         array(
  65.                             'username' => $_POST['username'],
  66.                             'password'  =>  $this->passHash($_POST['password'])
  67.                     ));
  68.  
  69.                 $key = sha1($userdata[0]->username . $userdata[0]->password . USER_IP);
  70.                 if(isset($_POST['remember'])) {
  71.                      setcookie('auth', $userdata[0]->id . '------' . $key, time() + 3600 * 24 * 10, '/', '127.0.0.1', false, true);
  72.                 }
  73.  
  74.                 if($userdata) {
  75.                     $db->save('UPDATE users SET last_online=:last_online WHERE id=:id',
  76.                         array(
  77.                                 'last_online'       =>      time(),
  78.                                 'id'                      =>      $userdata[0]->id
  79.                             ));
  80.                     $_SESSION['Auth'] = (array)$userdata[0];
  81.                     $core->go('home');
  82.                     //$core::setMessage('Correct login', 'notification');
  83.                 } else {
  84.                     $core::setMessage('Incorrect login details', 'notification-modal');
  85.                 }
  86.             } else {
  87.                 $core::setMessage($core->Write('errors.empty_fields'), 'notification-modal');
  88.             }
  89.         }
  90.     }
  91.  
  92.  
  93.  
  94.  
  95.     public function addUser() {
  96.     global $db, $core;
  97.         if(isset($_POST['signup']) && $_GET['action'] == "register") {
  98.             if(!empty($_POST['username']) && !empty($_POST['newpass']) && !empty($_POST['password_confirm']) && !empty($_POST['captcha']) && !empty($_POST['email'])) {
  99.  
  100.                 if($core->verifyCaptcha()) {
  101.                     if($this->checkUsername($_POST['username']) > 0) {
  102.                         $core::setMessage('Username taken','notification mauto');
  103.                     }
  104.                     //elseif(!preg_match('/^$[aZ-09]*/', subject))
  105.                 elseif($this->checkEmail($_POST['email']) > 0) {
  106.                     $core::setMessage('Email already in use.','notification-modal');
  107.                 }
  108.                 elseif(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  109.                     $core::setMessage('Please enter a validate email', 'notification-modal');
  110.                 }
  111.                 elseif(strlen($_POST['newpass']) < 6) {
  112.                     $core::setMessage('Your password should be at least 6 characters', 'notification-modal');
  113.                 }
  114.                 elseif($_POST['newpass'] !== $_POST['password_confirm']) {
  115.                     $core::setMessage('Your passwords doesn\'t  match. Please try again.', 'notification-modal');
  116.                 }
  117.  
  118.                 else {
  119.                         // Let's fucking add our user to DB.
  120.                         $db->save('INSERT INTO users (username, mail, password, activity_points, credits, motto, account_created, vip_points, look, ip_reg) VALUES(:username, :mail, :password, :activity_points, :credits, :motto, :account_created, :vip_points, :look, :ip_reg) ', array(
  121.                             'username'              =>         $_POST['username'],
  122.                             'mail'                      =>  $_POST['email'],
  123.                             'password'              =>  $this->passHash($_POST['newpass']),
  124.                             'activity_points'       =>  '1500',
  125.                             'credits'                   =>  '100000',
  126.                             'motto'                    =>  'Welcome to ' . SNAME,
  127.                             'account_created' =>  time(),
  128.                             'vip_points'            => '5',
  129.                             'look'                      =>  'hr-115-42.hd-190-1.ch-215-62.lg-285-91.sh-290-62',
  130.                             'ip_reg'                   => USER_IP
  131.  
  132.  
  133.                         ));
  134.  
  135.                         //mail("localhost", "Welcome to '".SNAME."' ", "Welcome to our website, fag!");
  136.                         $core->go('home');
  137.                         $_SESSION['logged']  = true;
  138.                         $_SESSION['Auth'] = array();
  139.                         $_SESSION['Auth']['username']  = $_POST['username'];
  140.                         $_SESSION['Auth']['password']  = $this->passHash($_POST['newpass']);
  141.  
  142.  
  143.                         // Email sending here:
  144.  
  145.                         $to = $_POST['email'];
  146.                         $subject = 'Welcome to ' . SNAME;
  147.                         $message = 'Hello <b>'.$_POST['username'].'</b>';
  148.                         $headers = 'From: no-replay@habboc.fr' . "\r\n" .
  149.                         'Reply-To: no-replay@habboc.fr' . "\r\n";
  150.  
  151.                         mail($to, $subject, $message, $headers);
  152.  
  153.                         exit();
  154.                     }
  155.                 } else {
  156.                     $core::setMessage('Wrong captcha.','notification-modal');
  157.                 }
  158.  
  159.                 } else {
  160.                     $core::setMessage('Please fill all in fucking fields.','notification-modal');
  161.                 }
  162.             }
  163.     }
  164.  
  165.     public function loggedIn() {
  166.         if(isset($_SESSION['Auth'])) {
  167.             return true;
  168.     } else {
  169.         return false;
  170.     }
  171. }
  172.  
  173.     public function checkLogged() {
  174.         global $core;
  175.         if(!$this->loggedIn()) {
  176.             $core->go('?auth=false');
  177.         }
  178.     }
  179.  
  180.     public function checkAuth() {
  181.         global $core;
  182.         if(!$this->loggedIn()) {
  183.         $core->go('?auth=false');
  184.         } /*elseif(isset($_COOKIE['remember_me']) && $this->loggedIn()) {
  185.             $core->go('home');
  186.         }**/
  187.     }
  188.  
  189.         public function checkCookie()  {
  190.         global $core;
  191.         if(isset($_COOKIE['auth'])) {
  192.             $core->go('home');
  193.         }
  194.     }
  195.  
  196.  
  197.     public function checkToken() {
  198.         if(isset($_SESSION['token'])) {
  199.                 if(isset($_GET['t']) && $_GET['t'] != $_SESSION['token']) {
  200.                 die('Looks like we got a badass over here');
  201.                 }
  202.         }
  203. }
  204.     public function userData() {
  205.         global $db, $core;
  206.         if(isset($_SESSION['Auth'])) {
  207.             $req = $db->query('SELECT * FROM users WHERE username=:username AND password=:password',
  208.                 array(
  209.                         'username'      =>  $_SESSION['Auth']['username'],
  210.                         'password'      =>  $_SESSION['Auth']['password']
  211.             ));
  212.  
  213.            return $req[0];
  214.  
  215.         } else {
  216.             echo "{unknown_user}";
  217.         }
  218.     }
  219.  
  220.  
  221.      public function resetPass($length = 8) {
  222.         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  223.         $charactersLength = strlen($characters);
  224.         $randomString = '';
  225.     for ($i = 0; $i < $length; $i++) {
  226.         $randomString .= $characters[rand(0, $charactersLength - 1)];
  227.     }
  228.         return $randomString;
  229.     }
  230.  
  231.     public function passwordReset(){
  232.         global $core, $db;
  233.         if(isset($_GET['action']) && $_GET['action'] == "resetpw") {
  234.             if(isset($_POST['email'])) {
  235.                          $core::setMessage('Password reset sucessfully, check your email. <br> If you don\'t see the email, you might check other places like Junk, spam, or other folders. ', 'notification mauto mbottom success');
  236.                     $passreset = $this->resetPass();
  237.                 if(!empty($_POST['email'])) {
  238.                     if($this->checkEmail($_POST['email']) == 0) {
  239.                         $core::setMessage('D\'oh! We could not find anything. Please try using another email.', 'notification-modal');
  240.                     } else {
  241.                          $db->save('UPDATE users SET password=:password WHERE mail=:mail LIMIT 1',
  242.                             array(
  243.                                     'password'      =>  $this->passHash($passreset),
  244.                                     'mail'             => $_POST['email']
  245.                         ));
  246.  
  247.                         $to = $_POST['email'];
  248.                         $subject = 'Your ' . SNAME . ' password has been reset.';
  249.                         $message = 'Dear user, <br>
  250.                        Your password has been reset, this is your new <b>'.SNAME.'</b> password:<br>
  251.                        <strong>'.$passreset.'</strong><hr>
  252.                        <a href="'.WWW.'/">CLICK HERE</a> to login back to your account.
  253.                        ';
  254.                         $headers = 'From: no-replay@habboc.nl' . "\r\n" .
  255.                         'Reply-To: no-replay@habboc.nl' . "\r\n";
  256.  
  257.                         mail($to, $subject, $message, $headers);
  258.  
  259.                     }
  260.                 } else {
  261.                     $core::setMessage('Please enter an email address!', 'notification-modal');
  262.  
  263.                 }
  264.             }
  265.         }
  266.     }
  267.  
  268.  
  269.     public function updateProfile() {
  270.         global $core, $db, $users;
  271.         if(isset($_POST['amigos']) && isset($_POST['motto'])  &&  isset($_GET['t']) && $_GET['action'] == 'updateprofile') {
  272.             $amigos = $_POST['amigos'];
  273.             $motto = $_POST['motto'];
  274.             $trade_lock = $_POST['trade_lock'];
  275.             if(!empty($motto)) {
  276.                $db->save('UPDATE users SET motto = :motto, block_newfriends=:block_newfriends, trade_lock =:trade_lock WHERE id=:id LIMIT 1',
  277.                     array(
  278.                                 'motto'                      =>     $motto,
  279.                                 'block_newfriends'  =>     $amigos,
  280.                                 'trade_lock'              =>     $trade_lock,
  281.                                 'id'                            =>     $users->userData()->id
  282.  
  283.                 ));
  284.                     $core::setMessage('Profile updated successfully!', 'notification-modal success');
  285.                     $core->debug($_POST);
  286.  
  287.             }
  288.         }
  289.     }
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement