|
| 1 | +# $Id$ |
| 2 | +# |
| 3 | +# |
| 4 | +#---------------------------------------------------------------------------- |
| 5 | +# |
| 6 | +# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved. |
| 7 | +# |
| 8 | +# Gmail: garbagecat10 |
| 9 | +# |
| 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. |
| 14 | +# |
| 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. |
| 19 | +# |
| 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 |
| 23 | +# |
| 24 | +#--------------------------------------------------------------------------- |
| 25 | +# |
| 26 | +# |
| 27 | + |
| 28 | + |
| 29 | +module Net |
| 30 | +class LDAP |
| 31 | + |
| 32 | + |
| 33 | +class Password |
| 34 | + class << self |
| 35 | + |
| 36 | + # Generate a password-hash suitable for inclusion in an LDAP attribute. |
| 37 | + # STUB: This is here to fulfill the requirements of an RFC, which one? |
| 38 | + # TODO, gotta do salted-sha and (maybe) salted-md5. |
| 39 | + # Should we provide sha1 as a synonym for sha1? I vote no because then |
| 40 | + # should you also provide ssha1 for symmetry? |
| 41 | + def generate( type, str ) |
| 42 | + case type |
| 43 | + when :md5 |
| 44 | + require 'md5' |
| 45 | + "{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }" |
| 46 | + when :sha |
| 47 | + require 'sha1' |
| 48 | + "{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }" |
| 49 | + # when ssha |
| 50 | + else |
| 51 | + raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" ) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + end |
| 56 | +end |
| 57 | + |
| 58 | + |
| 59 | +end # class LDAP |
| 60 | +end # module Net |
| 61 | + |
| 62 | + |
0 commit comments