Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'casserver/authenticators/base'
- require 'rubygems'
- require 'active_record'
- class CASServer::Authenticators::SQL_SHA256 < CASServer::Authenticators::Base
- def validate(credentials)
- read_standard_credentials(credentials)
- raise CASServer::AuthenticatorError, "Cannot validate credentials because the authenticator hasn't yet been configured" unless @options
- raise CASServer::AuthenticatorError, "Invalid authenticator configuration!" unless @options[:database]
- CASUser.establish_connection @options[:database]
- CASUser.set_table_name @options[:user_table] || "users"
- username_column = @options[:username_column] || 'username'
- password_column = @options[:password_column] || 'password'
- user = CASUser.find(:first, :conditions => ["#{username_column} = ?", @username])
- return false unless user
- user.authenticated?(@password)
- end
- class CASUser < ActiveRecord::Base
- def authenticated?(password)
- hashed_password == Digest::SHA256.hexdigest("--#{salt}--#{password}--")
- end
- end
- end
Add Comment
Please, Sign In to add comment