Guest User

Untitled

a guest
Aug 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. if($_POST['action'] == 'call_this') {
  2. checkUser();
  3. }
  4.  
  5. function checkUser() {
  6. $url = 'myshopurl'; //code uses actual url
  7. $key = 'mykey'; //code uses actual key
  8. $debug = true;
  9. require_once('./PSWebServiceLibrary.php');
  10.  
  11. $webService = new PrestaShopWebservice($url, $key, $debug);
  12. $COOKIE_KEY = 'mycookiekey'; //code uses actual cookie key
  13. $password = $_REQUEST['password'];
  14. $email = $_REQUEST['email'];
  15.  
  16. $optUser = array(
  17. 'resource' => 'customers',
  18. 'filter[email]' => '[' . $email . ']',
  19. 'display' => '[id,email,lastname,firstname,passwd]'
  20. );
  21.  
  22. $resultUser = ($webService->get($optUser));
  23.  
  24. $json = json_encode($resultUser);
  25. echo $json;
  26.  
  27. foreach ($resultUser->customers->customer as $info) {
  28.  
  29.  
  30. $salt = substr($info->passwd, strrpos($info->passwd, ':') + 1, 2);
  31.  
  32. $ZCpassword = md5($COOKIE_KEY . $password) . ':' . $salt;
  33.  
  34. // Check if password comparison is true or false
  35. if (password_verify($password, $info->passwd) == true) {
  36. session_start();
  37. $response = array();
  38. $response['status'] = 'success';
  39. $response['message'] = "You did it!";
  40. setcookie("userId", $info->id);
  41. header('Content-type: application/json');
  42. echo json_encode($response);
  43. } else {
  44. $response = array();
  45. $response['status'] = 'error';
  46. $response['message'] = 'Wrong password';
  47. header('Content-type: application/json');
  48. echo json_encode($response);
  49. }
  50. }
Add Comment
Please, Sign In to add comment