Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. protected function logar($user,$pass){
  2.             try{
  3.                 $cnn = new models\Connect;
  4.                 $stmt = $cnn->pdo->prepare("SELECT ID FROM ta_users WHERE User=:l_u AND Pass=:l_p");
  5.                 $param = array(
  6.                     ":l_u" => $user,
  7.                     ":l_p" => $pass,
  8.                 );
  9.                 $stmt->execute($param);
  10.                 if($stmt->rowCount() > 0){
  11.                     return true;
  12.                 }else{
  13.                     return false;
  14.                 }
  15.             }catch(PDOException $ex){
  16.                 return "ERROR 02 : Login.php {$ex->getMessage()}";
  17.             }
  18.         }
  19.         public static function tryLogin(){
  20.             try{
  21.                 if(count($_POST) > 0){
  22.                     if(isset($_POST['submited']) and $_POST['submited'] == "true"){
  23.                         if(isset($_POST['login_user']) and $_POST['login_pass']){
  24.                             $login_user = trim(strip_tags($_POST['login_user']));
  25.                             $login_pass = trim(strip_tags($_POST['login_pass']));
  26.                             $try_logar = self::logar($login_user, md5($login_pass));
  27.                             if($try_logar){
  28.                                 setcookie('dbd12dcea2f9acc4b9ec58c3207d471f', base64_encode($login_user), time()+3600*24);
  29.                                 setcookie('fd018c0295d66d99cc99b29a88b69b2a', base64_encode(md5($login_pass)), time()+3600*24);
  30.                                 $arrayReturn = array(
  31.                                     'message' => "logged",
  32.                                 );
  33.                                 echo json_encode($arrayReturn);
  34.                                 exit;
  35.                                 die;
  36.                             }else{
  37.                                 $arrayReturn = array(
  38.                                     'message' => "failed",
  39.                                     'error' => $try_logar,
  40.                                 );
  41.                                 echo json_encode($arrayReturn);
  42.                             }
  43.                             exit;
  44.                             die;
  45.                         }else{
  46.                             $arrayReturn = array(
  47.                                 "message" => "empty",
  48.                             );
  49.                             echo json_encode($arrayReturn);
  50.                             exit;
  51.                             die;
  52.                         }
  53.                     }
  54.                 }
  55.             }catch(PDOException $ex){
  56.                 return "ERROR 01 Login.php : {$ex->getMessage()}";
  57.                 exit;
  58.                 die;
  59.             }          
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement