Sha256: 3a9692b3cb19800bf410889f2bce603bc56f4a2c0b4ec5fe6d2c6d3bf6e08f43
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
require 'active_ldap/user_password' class LdapUser < ActiveLdap::Base ldap_mapping :prefix => "ou=Users", :classes => ["person"], :dn_attribute => "cn" N_("LdapUser|Password") N_("LdapUser|Password confirmation") attr_accessor :password validates_presence_of :password, :password_confirmation, :if => :password_required? validates_length_of :password, :within => 4..40, :if => :password_required? validates_confirmation_of :password, :if => :password_required? before_save :encrypt_password class << self def authenticate(dn, password) user = find(dn) user.authenticated?(password) ? user : nil rescue ActiveLdap::EntryNotFound nil end end def authenticated?(password) establish_connection(:password => password) true rescue ActiveLdap::AuthenticationError, ActiveLdap::LdapError::UnwillingToPerform false end private def encrypt_password return if password.blank? hash_type = "ssha" if /\A\{([A-Z][A-Z\d]+)\}/ =~ userPassword.to_s hash_type = $1.downcase end self.user_password = ActiveLdap::UserPassword.send(hash_type, password) end def password_required? user_password.blank? or !password.blank? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-activeldap-0.8.3.1 | examples/al-admin/app/models/ldap_user.rb |