Files

Devise::Models::Unix2ChkpwdAuthenticatable

Public Class Methods

included(base) click to toggle source
# File lib/devise_unix2_chkpwd_authenticatable/model.rb, line 8
def self.included(base)
  base.class_eval do
    extend ClassMethods
    attr_accessor :password
  end
end

Public Instance Methods

clean_up_passwords() click to toggle source

Set password to nil

# File lib/devise_unix2_chkpwd_authenticatable/model.rb, line 16
def clean_up_passwords
  self.password = nil
end
unix2_chkpwd(login, passwd) click to toggle source
# File lib/devise_unix2_chkpwd_authenticatable/model.rb, line 20
def unix2_chkpwd(login, passwd)
  Rails.logger.info "*** UNIX2_CHKPWD: checking password for user #{login.inspect}"

  success = nil

  # check Ruby version
  if RUBY_VERSION.match /^1.8/
    # open3 does not return the exit status correctly
    # use echo to print it to stdout
    Open3.popen3("/sbin/unix2_chkpwd passwd '#{escape_quotes login}'; echo $?") do |stdin, stdout, stderr|
      stdin.write passwd
      stdin.close
      error = stderr.read
      Rails.logger.error "*** UNIX2_CHKPWD: Password check failed: #{error}" unless error.empty?
      success = stdout.read == "0\n"
   end
  else
    # Ruby 1.9 (or higher)
    Open3.popen3("/sbin/unix2_chkpwd", "passwd", login) do |stdin, stdout, stderr, wait_thr|
      stdin.write passwd
      stdin.close
      error = stderr.read
      Rails.logger.error "*** UNIX2_CHKPWD: Password check failed: #{error}" unless error.empty?
      success = wait_thr.value.exitstatus == 0
    end
  end

  return success
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.