Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function logar($user,$pass){
- try{
- $cnn = new models\Connect;
- $stmt = $cnn->pdo->prepare("SELECT ID FROM ta_users WHERE User=:l_u AND Pass=:l_p");
- $param = array(
- ":l_u" => $user,
- ":l_p" => $pass,
- );
- $stmt->execute($param);
- if($stmt->rowCount() > 0){
- return true;
- }else{
- return false;
- }
- }catch(PDOException $ex){
- return "ERROR 02 : Login.php {$ex->getMessage()}";
- }
- }
- public static function tryLogin(){
- try{
- if(count($_POST) > 0){
- if(isset($_POST['submited']) and $_POST['submited'] == "true"){
- if(isset($_POST['login_user']) and $_POST['login_pass']){
- $login_user = trim(strip_tags($_POST['login_user']));
- $login_pass = trim(strip_tags($_POST['login_pass']));
- $try_logar = self::logar($login_user, md5($login_pass));
- if($try_logar){
- setcookie('dbd12dcea2f9acc4b9ec58c3207d471f', base64_encode($login_user), time()+3600*24);
- setcookie('fd018c0295d66d99cc99b29a88b69b2a', base64_encode(md5($login_pass)), time()+3600*24);
- $arrayReturn = array(
- 'message' => "logged",
- );
- echo json_encode($arrayReturn);
- exit;
- die;
- }else{
- $arrayReturn = array(
- 'message' => "failed",
- 'error' => $try_logar,
- );
- echo json_encode($arrayReturn);
- }
- exit;
- die;
- }else{
- $arrayReturn = array(
- "message" => "empty",
- );
- echo json_encode($arrayReturn);
- exit;
- die;
- }
- }
- }
- }catch(PDOException $ex){
- return "ERROR 01 Login.php : {$ex->getMessage()}";
- exit;
- die;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement