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.

44 lines
1.2 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. throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE);
  17. }
  18. $password = $this->stringHash($password,$storeUsersModel->salt);
  19. if($storeUsersModel->password === $password){
  20. return $storeUsersModel;
  21. }else{
  22. throw new ErrorCodeException(ErrorCode::STORE_LOGIN_ERROR);
  23. }
  24. }
  25. public function check()
  26. {
  27. // TODO: Implement check() method.
  28. }
  29. public function undo()
  30. {
  31. // TODO: Implement undo() method.
  32. }
  33. function stringHash($password,$salt)
  34. {
  35. $authkey = config('login.authkey');
  36. $password = "{$password}-{$salt}-{$authkey}";
  37. return sha1($password);
  38. }
  39. }