You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

6 years ago
6 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Model\v3\StoreUsers;
  6. use App\Service\v3\Interfaces\StoreLoginServiceInterface;
  7. class StoreLoginService implements StoreLoginServiceInterface
  8. {
  9. public function do($account,$password)
  10. {
  11. $storeUsersModel = StoreUsers::query()->where([
  12. ['username','=',$account],
  13. ['status','=',2]
  14. ])->first();
  15. if(empty($storeUsersModel)){
  16. $msg = ["StoreLoginService"=>"1","account"=>$account];
  17. throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,json_encode($msg));
  18. }
  19. $password = $this->stringHash($password,$storeUsersModel->salt);
  20. if($storeUsersModel->password === $password){
  21. return $storeUsersModel;
  22. }else{
  23. throw new ErrorCodeException(ErrorCode::STORE_LOGIN_ERROR);
  24. }
  25. }
  26. public function check()
  27. {
  28. // TODO: Implement check() method.
  29. }
  30. public function undo()
  31. {
  32. // TODO: Implement undo() method.
  33. }
  34. function stringHash($password,$salt)
  35. {
  36. $authkey = config('login.authkey');
  37. $password = "{$password}-{$salt}-{$authkey}";
  38. return sha1($password);
  39. }
  40. }