Chris@0: # $Id: psw.rb 73 2006-04-24 21:59:35Z blackhedd $ Chris@0: # Chris@0: # Chris@0: #---------------------------------------------------------------------------- Chris@0: # Chris@0: # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved. Chris@0: # Chris@0: # Gmail: garbagecat10 Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or modify Chris@0: # it under the terms of the GNU General Public License as published by Chris@0: # the Free Software Foundation; either version 2 of the License, or Chris@0: # (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Chris@0: # Chris@0: #--------------------------------------------------------------------------- Chris@0: # Chris@0: # Chris@0: Chris@0: Chris@0: module Net Chris@0: class LDAP Chris@0: Chris@0: Chris@0: class Password Chris@0: class << self Chris@0: Chris@0: # Generate a password-hash suitable for inclusion in an LDAP attribute. Chris@0: # Pass a hash type (currently supported: :md5 and :sha) and a plaintext Chris@0: # password. This function will return a hashed representation. Chris@0: # STUB: This is here to fulfill the requirements of an RFC, which one? Chris@0: # TODO, gotta do salted-sha and (maybe) salted-md5. Chris@0: # Should we provide sha1 as a synonym for sha1? I vote no because then Chris@0: # should you also provide ssha1 for symmetry? Chris@0: def generate( type, str ) Chris@0: case type Chris@0: when :md5 Chris@0: require 'md5' Chris@0: "{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }" Chris@0: when :sha Chris@0: require 'sha1' Chris@0: "{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }" Chris@0: # when ssha Chris@0: else Chris@0: raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" ) Chris@0: end Chris@0: end Chris@0: Chris@0: end Chris@0: end Chris@0: Chris@0: Chris@0: end # class LDAP Chris@0: end # module Net Chris@0: Chris@0: