Advertisement
Guest User

Untitled

a guest
May 5th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.61 KB | None | 0 0
  1. <?php
  2. class user_manage{
  3.     public  $login, $pass;
  4.     private $noRegistredMsg   = "Usuário Inexistente ";
  5.     private $noCorrectpassMsg = "Senha Inválida ";
  6.     private $nologgedMsg      = "Refaça o Login ";
  7.     private $loggedMsg        = "Olá ";
  8.    
  9.     private $userRegistredMsg   = "Este nome de usuário já foi cadastrado ";
  10.     private $mailRegistredMsg   = "Este email já foi cadastrado ";
  11.     private $inputEmptyMsg      = "Favor preencha todos os campos ";
  12.     private $mailInvalidMsg     = "Email inválido";
  13.     private $userInvalidMsg     = "Caracteres inválidos no nome de usuário ";
  14.     private $userSizeInvalidMsg = "Insira no máximo 6 caracteres no nome de usuário ";
  15.     private $passSizeInvalidMsg = "Insira uma senha com pelo menos 6 caracteres ";
  16.    
  17.     private $mailconfirmMsg      = "Email confirmado com sucesso ";
  18.     private $mailconfirmErrorMsg = "Não foi possivel confirmar seu email ";
  19.    
  20.     private $updatepassMsg       = "Senha atualizada ";
  21.     private $updatepassErrorMsg  = "Não foi possível atualizar sua senha ";
  22.  
  23.     private $dbuser = "root";
  24.     private $dbpass = "";
  25.    
  26.        
  27. function database_connect(){
  28.         $sql = mysql_connect('localhost', $this->dbuser, $this->dbpass);
  29.         mysql_select_db('bugs', $sql);
  30.         return $sql;
  31.     }
  32.    
  33.    
  34. function validate($type,$login,$pass){
  35.         $db = $this->database_connect();
  36.         $userSearch = mysql_query("SELECT * FROM usuarios WHERE user='".$login."'",$db);
  37.        
  38.         $linha = mysql_fetch_array($userSearch);
  39.             if($linha["pass"] == $pass && $linha["tipo"] == $type) {
  40.                 $this->logged=true;}
  41.             else{ $this->loginstatus = $this->nologgedMsg; }
  42.         }
  43.        
  44.        
  45. function login($login,$pass){
  46.         $db = $this->database_connect();
  47.         $userSearch = mysql_query("SELECT * FROM usuarios WHERE user='".$login."'",$db);
  48.         $mailSearch = mysql_query("SELECT * FROM usuarios WHERE mail='".$login."'",$db);
  49.        
  50.         if(mysql_num_rows($userSearch) == 0 && mysql_num_rows($mailSearch) == 0) {
  51.         $this->loginstatus = $this->noRegistredMsg;
  52.         }else{
  53.         ob_start();
  54.         session_start();
  55.         $linha = mysql_fetch_array($userSearch);
  56.             if($linha["pass"] == $pass) {
  57.                 $_session["pass"] = $linha["pass"];
  58.                 $_session["type"] = $linha["tipo"];
  59.                 $_session["user"] = $linha["user"];
  60.                 $_session["uid"]  = $linha["uid"];
  61.                 $_session["time"] = time();
  62.                 $this->logged=true;
  63.                 $this->loginstatus = $this->loggedMsg.$linha["user"]; }
  64.             else{ $this->loginstatus = $this->noCorrectpassMsg; }
  65.             }
  66.         }
  67.        
  68. function register($user, $mail, $pass, $type){
  69.         $db = $this->database_connect();
  70.         $userSearch = mysql_query("SELECT * FROM usuarios WHERE user='".$user."'",$db);
  71.         $mailSearch = mysql_query("SELECT * FROM usuarios WHERE mail='".$mail."'",$db);
  72.        
  73.         if(empty($user)||empty($pass)||empty($mail)){
  74.         $this->registerstatus = $this->inputEmptyMsg ;}
  75.          elseif(!preg_match("/^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/",$mail)){
  76.         $this->registerstatus = $this->mailInvalidMsg ;}
  77.          elseif(!preg_match("/^[\w\d]+/",$user)){
  78.         $this->registerstatus = $this->userInvalidMsg ;}
  79.          elseif(strlen($user) > 6){
  80.         $this->registerstatus = $this->userSizeInvalidMsg ;}
  81.          elseif(strlen($pass) < 6 || strlen($pass) > 15 ){
  82.         $this->registerstatus = $this->passSizeInvalidMsg ;}
  83.          elseif(mysql_num_rows($mailSearch) != null) {
  84.         $this->registerstatus = $this->mailRegistredMsg;}
  85.          elseif(mysql_num_rows($userSearch) != null){
  86.         $this->registerstatus = $this->userRegistredMsg;}
  87.          else{
  88.             $this->registerstatus = true;
  89.             mysql_query("INSERT INTO usuarios (user,pass,mail,tipo,status) VALUES ('".$user."','".sha1($pass)."','".$mail."','user','1')");
  90.             $this->login($user,$pass);}
  91.         }
  92.        
  93. function mailconfirm($mail, $auth){
  94.         $db = $this->database_connect();
  95.         $authSearch = mysql_query("SELECT mail FROM usuarios WHERE auth='".$auth."'",$db);
  96.        
  97.         if(mysql_num_rows($authSearch) != null) {
  98.         mysql_query("UPDATE usuarios SET status='2' WHERE mail='".$mail."'");
  99.         $this->mailconfirmstatus = $this->mailconfirmMsg;}
  100.          else{
  101.         $this->mailconfirmstatus = $this->mailconfirmErrorMsg;}
  102.         }
  103.  
  104. function updatepass($user, $oldpass, $newpass){
  105.         $db = $this->database_connect();
  106.         $userSearch = mysql_query("SELECT * FROM usuarios WHERE user='".$user."'",$db);
  107.         $this->login($user, $oldpass);
  108.        
  109.         if(strlen($newpass) < 6 || strlen($newpass) > 15){
  110.         $this->updatepassstatus = $this->passSizeInvalidMsg ;}
  111.          elseif($this->loginstatus == $this->loggedMsg.$user){
  112.         mysql_query("UPDATE usuarios SET pass='".sha1($newpass)."' WHERE user='".$user."'",$db) or die(mysql_error());
  113.         $this->updatepassstatus = $this->updatepassMsg;}
  114.          else{
  115.         $this->updatepassstatus = $this->updatepassErrorMsg;}
  116.         }  
  117.    
  118. }
  119.        
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement