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