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