To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 25 / 25e20e75adcb2337c7b7589449cc334604a57456.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.89 KB)
| 1 |
# $Id: psw.rb 73 2006-04-24 21:59:35Z blackhedd $ |
|---|---|
| 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 |
# 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 ) |
| 44 |
case type |
| 45 |
when :md5 |
| 46 |
require 'md5' |
| 47 |
"{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }"
|
| 48 |
when :sha |
| 49 |
require 'sha1' |
| 50 |
"{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }"
|
| 51 |
# when ssha |
| 52 |
else |
| 53 |
raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
|
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
end |
| 58 |
end |
| 59 |
|
| 60 |
|
| 61 |
end # class LDAP |
| 62 |
end # module Net |
| 63 |
|
| 64 |
|