Advertisement
adhieresthenes

Login API ERP

Sep 11th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.07 KB | None | 0 0
  1. <?php
  2. /*****************************************
  3. *   API Version : 0.1
  4. *   API Service : Commercial Back Office Server
  5. ******************************************/
  6.  
  7. //load database config and other data libs
  8. require_once ("../../app/config/config.php");
  9. require_once ("../../app/general/Security.php");
  10. require      ("../../app/securimage/Securimage.php");
  11. //require_once ("../../app/config/FUnction_connect.php");
  12.  
  13.  
  14. //API CALL DATA EXAMPLE & TEST
  15. /************************************
  16. ** Developer can modified these code if it neccessary, otherwise you can ignore it.
  17. ** User data from DB being parsed to json data!
  18. ** password decryptor https://md5hashing.net/hash
  19. /************************************/
  20.  
  21. //cbois
  22. /*example method url call : http://localhost/poc-erp/restapi/v0.1/cbos?act=login&username=admin&password=12345678bC */
  23.  
  24. $act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
  25.    
  26.     switch ($act) {
  27.         /*case 'registration':
  28.             //registration
  29.             # code...
  30.             $idobu = ($_REQUEST['nomorobu']);
  31.             $vehicenum = strtolower($_REQUEST['nomorobu']);
  32.             $username = strtolower($_REQUEST['nomorkendaraan']);
  33.             $email = strtolower($_REQUEST['email']);
  34.             $password = $_REQUEST['password'];
  35.             $handphone = $_REQUEST['mobnumb'];
  36.             break;*/
  37.  
  38.         case 'login':
  39.             //login validation
  40.             # code...
  41.             $id = empty($_REQUEST['id']);
  42.             $user = $_REQUEST['username'];
  43.             $pass = ($_REQUEST['password']);  
  44.             $password = hash('sha512', $pass);
  45.            
  46.             //query data
  47.             //query = ("SELECT * from m_user");
  48.             $stmt = $mysqli->prepare("SELECT id, username, password, salt
  49.             FROM m_user
  50.             WHERE (email = ? OR username = ?) AND active = 1
  51.             LIMIT 1");
  52.            
  53.             $stmt->bind_param('ss', $email, $user);
  54.            
  55.             $stmt->execute();    // Execute the prepared query.
  56.             $stmt->store_result();
  57.      
  58.             // get variables from result.
  59.             $stmt->bind_result($user_id, $username, $db_password, $salt);
  60.             $stmt->fetch();
  61.  
  62.             // hash the password with the unique salt.
  63.             $password = hash('sha512', $password . $salt);
  64.  
  65.                 //query2
  66.                 $query = ("SELECT * FROM m_user WHERE username='$user' AND password='$password' ");
  67.                
  68.            
  69.             $result = $mysqli->query($query);
  70.             $data = array();
  71.             while ($row = mysqli_fetch_assoc($result)){
  72.                
  73.                 $data[]= array(
  74.                     "id" => $row['id'],
  75.                     "username" => $row['username'],
  76.                     "password" => $row['password'],
  77.                    
  78.                     );
  79.             }
  80.  
  81.              if(!empty($data)){
  82.  
  83.             //respon data
  84.             $json = array(
  85.                 'status' => 'Success',
  86.                 'data' => $data
  87.             );
  88.  
  89.             }else{
  90.  
  91.             $json = array(
  92.                         'status' => 'error, 400',
  93.                         'msg' => 'wrong username or password ',
  94.                         );
  95.             }
  96.               echo json_encode($json);
  97.            
  98.  
  99.  
  100.             /*echo '<pre>';
  101.             print_r($data);
  102.             echo '</pre>';*/
  103.             break;
  104.  
  105.         case 'topup':
  106.             # code...
  107.            
  108.  
  109.             break;
  110.  
  111.         default:
  112.             # code...
  113.             echo "akhir";
  114.             break;
  115.     }
  116.  
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement