ObserverConfig.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\User\Model\Backend\Config;
  7. /**
  8. * User backend observer helper class
  9. */
  10. class ObserverConfig
  11. {
  12. /**
  13. * Backend configuration interface
  14. *
  15. * @var \Magento\Backend\App\ConfigInterface
  16. */
  17. protected $backendConfig;
  18. /**
  19. * @param \Magento\Backend\App\ConfigInterface $backendConfig
  20. */
  21. public function __construct(
  22. \Magento\Backend\App\ConfigInterface $backendConfig
  23. ) {
  24. $this->backendConfig = $backendConfig;
  25. }
  26. /**
  27. * Check if latest password is expired
  28. *
  29. * @param array $latestPassword
  30. * @return bool
  31. */
  32. public function _isLatestPasswordExpired($latestPassword)
  33. {
  34. if (!isset($latestPassword['last_updated']) || $this->getAdminPasswordLifetime() == 0) {
  35. return false;
  36. }
  37. return (int)$latestPassword['last_updated'] + $this->getAdminPasswordLifetime() < time();
  38. }
  39. /**
  40. * Get admin lock threshold from configuration
  41. * @return int
  42. */
  43. public function getAdminLockThreshold()
  44. {
  45. return 60 * (int)$this->backendConfig->getValue('admin/security/lockout_threshold');
  46. }
  47. /**
  48. * Check whether password change is forced
  49. *
  50. * @return bool
  51. */
  52. public function isPasswordChangeForced()
  53. {
  54. return (bool)(int)$this->backendConfig->getValue('admin/security/password_is_forced');
  55. }
  56. /**
  57. * Get admin password lifetime
  58. *
  59. * @return int
  60. */
  61. public function getAdminPasswordLifetime()
  62. {
  63. return 86400 * (int)$this->backendConfig->getValue('admin/security/password_lifetime');
  64. }
  65. /**
  66. * Get admin maximum security failures from config
  67. *
  68. * @return int
  69. */
  70. public function getMaxFailures()
  71. {
  72. return (int)$this->backendConfig->getValue('admin/security/lockout_failures');
  73. }
  74. }