internal.rb 617 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. module Auth::Internal
  3. # rubocop:disable Style/ModuleFunction
  4. extend self
  5. def check(username, password, _config, user)
  6. # return if no user exists
  7. return false if !username
  8. return false if !user
  9. if PasswordHash.legacy?(user.password, password)
  10. update_password(user, password)
  11. return user
  12. end
  13. return false if !PasswordHash.verified?(user.password, password)
  14. user
  15. end
  16. private
  17. def update_password(user, password)
  18. user.password = PasswordHash.crypt(password)
  19. user.save
  20. end
  21. end