password_check.rb 625 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::PasswordCheck < Service::Base
  3. attr_reader :user, :password
  4. def initialize(user:, password:)
  5. super()
  6. @user = user
  7. @password = password
  8. end
  9. def execute
  10. Auth
  11. .new(user.login, password, only_verify_password: true)
  12. .valid!
  13. token = Token.create(action: 'PasswordCheck', user_id: user.id, persistent: false, expires_at: 1.hour.from_now)
  14. {
  15. success: true,
  16. token: token.token,
  17. }
  18. rescue Auth::Error::AuthenticationFailed
  19. {
  20. success: false,
  21. }
  22. end
  23. end