CredentialsValidator.php 1010 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model;
  7. use Magento\Framework\Exception\InputException;
  8. /**
  9. * Validator Helper for user credentials
  10. */
  11. class CredentialsValidator
  12. {
  13. /**
  14. * Validate user credentials
  15. *
  16. * @param string $username
  17. * @param string $password
  18. * @throws InputException
  19. * @return void
  20. */
  21. public function validate($username, $password)
  22. {
  23. $exception = new InputException();
  24. if (!is_string($username) || strlen($username) == 0) {
  25. $exception->addError(__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'username']));
  26. }
  27. if (!is_string($password) || strlen($password) == 0) {
  28. $exception->addError(__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'password']));
  29. }
  30. if ($exception->wasErrorAdded()) {
  31. throw $exception;
  32. }
  33. }
  34. }