internal.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Auth
  3. class Backend
  4. class Internal < Auth::Backend::Base
  5. private
  6. # Validation against the internal database.
  7. #
  8. # @returns [Boolean] true if the validation works, otherwise false.
  9. def authenticated?
  10. return true if hash_matches?
  11. auth.increase_login_failed_attempts = true
  12. false
  13. end
  14. # Overwrites the default behaviour to only perform this authentication if an internal password exists.
  15. #
  16. # @returns [Boolean] true if a internal password for the user is present.
  17. def perform?
  18. return false if !user.verified && user.source == 'signup'
  19. user.password.present?
  20. end
  21. def hash_matches?
  22. # makes sure that very long strings supplied as password
  23. # rejected early and not even tried to match to password
  24. if !PasswordPolicy::MaxLength.valid? password
  25. return false
  26. end
  27. # Because of legacy reason a special check exists and afterwards the
  28. # password will be saved in the current format.
  29. if PasswordHash.legacy?(user.password, password)
  30. user.update!(password: password)
  31. return true
  32. end
  33. PasswordHash.verified?(user.password, password)
  34. end
  35. end
  36. end
  37. end