annotate vendor/plugins/ruby-net-ldap-0.0.4/lib/net/ldap/psw.rb @ 1477:f2ad2199b49a bibplugin_integration

Close obsolete branch bibplugin_integration
author Chris Cannam
date Fri, 30 Nov 2012 14:41:31 +0000
parents 513646585e45
children
rev   line source
Chris@0 1 # $Id: psw.rb 73 2006-04-24 21:59:35Z blackhedd $
Chris@0 2 #
Chris@0 3 #
Chris@0 4 #----------------------------------------------------------------------------
Chris@0 5 #
Chris@0 6 # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
Chris@0 7 #
Chris@0 8 # Gmail: garbagecat10
Chris@0 9 #
Chris@0 10 # This program is free software; you can redistribute it and/or modify
Chris@0 11 # it under the terms of the GNU General Public License as published by
Chris@0 12 # the Free Software Foundation; either version 2 of the License, or
Chris@0 13 # (at your option) any later version.
Chris@0 14 #
Chris@0 15 # This program is distributed in the hope that it will be useful,
Chris@0 16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 18 # GNU General Public License for more details.
Chris@0 19 #
Chris@0 20 # You should have received a copy of the GNU General Public License
Chris@0 21 # along with this program; if not, write to the Free Software
Chris@0 22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Chris@0 23 #
Chris@0 24 #---------------------------------------------------------------------------
Chris@0 25 #
Chris@0 26 #
Chris@0 27
Chris@0 28
Chris@0 29 module Net
Chris@0 30 class LDAP
Chris@0 31
Chris@0 32
Chris@0 33 class Password
Chris@0 34 class << self
Chris@0 35
Chris@0 36 # Generate a password-hash suitable for inclusion in an LDAP attribute.
Chris@0 37 # Pass a hash type (currently supported: :md5 and :sha) and a plaintext
Chris@0 38 # password. This function will return a hashed representation.
Chris@0 39 # STUB: This is here to fulfill the requirements of an RFC, which one?
Chris@0 40 # TODO, gotta do salted-sha and (maybe) salted-md5.
Chris@0 41 # Should we provide sha1 as a synonym for sha1? I vote no because then
Chris@0 42 # should you also provide ssha1 for symmetry?
Chris@0 43 def generate( type, str )
Chris@0 44 case type
Chris@0 45 when :md5
Chris@0 46 require 'md5'
Chris@0 47 "{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }"
Chris@0 48 when :sha
Chris@0 49 require 'sha1'
Chris@0 50 "{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }"
Chris@0 51 # when ssha
Chris@0 52 else
Chris@0 53 raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
Chris@0 54 end
Chris@0 55 end
Chris@0 56
Chris@0 57 end
Chris@0 58 end
Chris@0 59
Chris@0 60
Chris@0 61 end # class LDAP
Chris@0 62 end # module Net
Chris@0 63
Chris@0 64