Guest User

Untitled

a guest
Mar 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. require 'casserver/authenticators/base'
  2. require 'rubygems'
  3. require 'active_record'
  4.  
  5.  
  6. class CASServer::Authenticators::SQL_SHA256 < CASServer::Authenticators::Base
  7.  
  8. def validate(credentials)
  9. read_standard_credentials(credentials)
  10.  
  11. raise CASServer::AuthenticatorError, "Cannot validate credentials because the authenticator hasn't yet been configured" unless @options
  12. raise CASServer::AuthenticatorError, "Invalid authenticator configuration!" unless @options[:database]
  13.  
  14. CASUser.establish_connection @options[:database]
  15. CASUser.set_table_name @options[:user_table] || "users"
  16.  
  17. username_column = @options[:username_column] || 'username'
  18. password_column = @options[:password_column] || 'password'
  19.  
  20. user = CASUser.find(:first, :conditions => ["#{username_column} = ?", @username])
  21. return false unless user
  22. user.authenticated?(@password)
  23.  
  24. end
  25.  
  26. class CASUser < ActiveRecord::Base
  27.  
  28. def authenticated?(password)
  29. hashed_password == Digest::SHA256.hexdigest("--#{salt}--#{password}--")
  30. end
  31. end
  32.  
  33. end
Add Comment
Please, Sign In to add comment