ruby-password-0.5.3/0000775000076400007640000000000010401646456014132 5ustar ianmacdianmacdruby-password-0.5.3/example/0000775000076400007640000000000010401644666015566 5ustar ianmacdianmacdruby-password-0.5.3/example/pwgen0000755000076400007640000000577110116437653016643 0ustar ianmacdianmacd#!/usr/bin/ruby -w # # $Id: pwgen,v 1.3 2004/09/04 22:20:27 ianmacd Exp $ # # Copyright (C) 2004 Ian Macdonald # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. require 'optparse' require 'ostruct' require 'password' class Optparse USAGE_BANNER = "Usage: pwgen [ OPTIONS ] [ password_length ] [ number_passwords ]" def self.parse(args) options = OpenStruct.new options.columns = $stdout.tty? options.one_case = $stdout.tty? ? Password::ONE_CASE : 0 options.one_digit = $stdout.tty? ? Password::ONE_DIGIT : 0 options.secure = false opts = OptionParser.new do |opts| opts.banner = USAGE_BANNER opts.on( "-C", "Print the generated passwords in columns") do options.columns = true end opts.on( "-1", "Don't print the generated passwords", " in columns") do options.columns = false end opts.on( "-c", "--[no-]capitalise", "--[no-]capitalize", "Include at least one capital letter in", " the password" ) do |opt| options.one_case = opt ? Password::ONE_CASE : 0 end opts.on( "-n", "--[no-]numerals", "Include at least one digit in the password" ) do |opt| options.one_digit = opt ? Password::ONE_DIGIT : 0 end opts.on( "-s", "--secure", "Generate completely random passwords" ) do options.secure = true end opts.on( "-v", "--version", "Display version and exit" ) do puts PWGEN_VERSION exit end opts.on_tail( "-h", "--help", "Display this usage message and exit" ) do puts opts exit end end opts.parse!(args) options end end PWGEN_VERSION = '0.5.2' TERM_WIDTH = 80 options = Optparse.parse(ARGV) unless [ 0, 2 ].include? ARGV.size puts Optparse::USAGE_BANNER exit 1 end length, number = *ARGV.map { |arg| arg.to_i } length ||= 8 generator = if length < 5 || options.secure Proc.new { Password.random( length ) } else Proc.new { Password.phonemic( length, options.one_case | options.one_digit ) } end columns = options.columns ? TERM_WIDTH / ( length + 1 ) : 1 columns = 1 if columns == 0 number ||= options.columns ? columns * 20 : 1 need_new_line = false 0.upto number - 1 do |n| if ! options.columns || n % columns == columns - 1 puts generator.call need_new_line = false else print generator.call, ' ' need_new_line = true end end puts if need_new_line ruby-password-0.5.3/example/example.rb0000755000076400007640000000240410034747222017541 0ustar ianmacdianmacd#!/usr/bin/ruby -w # # $Id: example.rb,v 1.7 2004/04/07 09:49:06 ianmacd Exp $ # # Copyright (C) 2002-2004 Ian Macdonald # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. require 'password' def handle_password( pw ) pw.check puts pw.crypt( `uname` == "Linux\n" ? Password::MD5 : Password::DES ) end begin my_string = Password.get( "Password with get: " ) handle_password( my_string ) rescue Password::WeakPassword => reason puts reason retry end begin my_string = Password.getc( "Password with getc: ", 'X' ) handle_password( my_string ) rescue Password::WeakPassword => reason puts reason retry end ruby-password-0.5.3/lib/0000775000076400007640000000000010401645251014670 5ustar ianmacdianmacdruby-password-0.5.3/lib/password.rb0000755000076400007640000002600410401645251017062 0ustar ianmacdianmacd# $Id: password.rb,v 1.24 2006/03/02 19:42:33 ianmacd Exp $ # # Version : 0.5.3 # Author : Ian Macdonald # # Copyright (C) 2002-2006 Ian Macdonald # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. require 'crack' require 'termios' # Ruby/Password is a collection of password handling routines for Ruby, # including an interface to CrackLib for the purposes of testing password # strength. # # require 'password' # # # Define and check a password in code # pw = Password.new( "bigblackcat" ) # pw.check # # # Get and check a password from the keyboard # begin # password = Password.get( "New password: " ) # password.check # rescue Password::WeakPassword => reason # puts reason # retry # end # # # Automatically generate and encrypt a password # password = Password.phonemic( 12, Password:ONE_CASE | Password::ONE_DIGIT ) # crypted = password.crypt # # class Password < String # This exception class is raised if an error occurs during password # encryption when calling Password#crypt. # class CryptError < StandardError; end # This exception class is raised if a bad dictionary path is detected by # Password#check. # class DictionaryError < StandardError; end # This exception class is raised if a weak password is detected by # Password#check. # class WeakPassword < StandardError; end VERSION = '0.5.3' # DES algorithm # DES = true # MD5 algorithm (see crypt(3) for more information) # MD5 = false # This flag is used in conjunction with Password.phonemic and states that a # password must include a digit. # ONE_DIGIT = 1 # This flag is used in conjunction with Password.phonemic and states that a # password must include a capital letter. # ONE_CASE = 1 << 1 # Characters that may appear in generated passwords. Password.urandom may # also use the characters + and /. # PASSWD_CHARS = '0123456789' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' # Valid salt characters for use by Password#crypt. # SALT_CHARS = '0123456789' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + './' # :stopdoc: # phoneme flags # CONSONANT = 1 VOWEL = 1 << 1 DIPHTHONG = 1 << 2 NOT_FIRST = 1 << 3 # indicates that a given phoneme may not occur first PHONEMES = { :a => VOWEL, :ae => VOWEL | DIPHTHONG, :ah => VOWEL | DIPHTHONG, :ai => VOWEL | DIPHTHONG, :b => CONSONANT, :c => CONSONANT, :ch => CONSONANT | DIPHTHONG, :d => CONSONANT, :e => VOWEL, :ee => VOWEL | DIPHTHONG, :ei => VOWEL | DIPHTHONG, :f => CONSONANT, :g => CONSONANT, :gh => CONSONANT | DIPHTHONG | NOT_FIRST, :h => CONSONANT, :i => VOWEL, :ie => VOWEL | DIPHTHONG, :j => CONSONANT, :k => CONSONANT, :l => CONSONANT, :m => CONSONANT, :n => CONSONANT, :ng => CONSONANT | DIPHTHONG | NOT_FIRST, :o => VOWEL, :oh => VOWEL | DIPHTHONG, :oo => VOWEL | DIPHTHONG, :p => CONSONANT, :ph => CONSONANT | DIPHTHONG, :qu => CONSONANT | DIPHTHONG, :r => CONSONANT, :s => CONSONANT, :sh => CONSONANT | DIPHTHONG, :t => CONSONANT, :th => CONSONANT | DIPHTHONG, :u => VOWEL, :v => CONSONANT, :w => CONSONANT, :x => CONSONANT, :y => CONSONANT, :z => CONSONANT } # :startdoc: # Turn local terminal echo on or off. This method is used for securing the # display, so that a soon to be entered password will not be echoed to the # screen. It is also used for restoring the display afterwards. # # If _masked_ is +true+, the keyboard is put into unbuffered mode, allowing # the retrieval of characters one at a time. _masked_ has no effect when # _on_ is +false+. You are unlikely to need this method in the course of # normal operations. # def Password.echo(on=true, masked=false) term = Termios::getattr( $stdin ) if on term.c_lflag |= ( Termios::ECHO | Termios::ICANON ) else # off term.c_lflag &= ~Termios::ECHO term.c_lflag &= ~Termios::ICANON if masked end Termios::setattr( $stdin, Termios::TCSANOW, term ) end # Get a password from _STDIN_, using buffered line input and displaying # _message_ as the prompt. No output will appear while the password is being # typed. Hitting [Enter] completes password entry. If _STDIN_ is not # connected to a tty, no prompt will be displayed. # def Password.get(message="Password: ") begin if $stdin.tty? Password.echo false print message if message end pw = Password.new( $stdin.gets || "" ) pw.chomp! ensure if $stdin.tty? Password.echo true print "\n" end end end # Get a password from _STDIN_ in unbuffered mode, i.e. one key at a time. # _message_ will be displayed as the prompt and each key press with echo # _mask_ to the terminal. There is no need to hit [Enter] at the end. # def Password.getc(message="Password: ", mask='*') # Save current buffering mode buffering = $stdout.sync # Turn off buffering $stdout.sync = true begin Password.echo(false, true) print message if message pw = "" while ( char = $stdin.getc ) != 10 # break after [Enter] putc mask pw << char end ensure Password.echo true print "\n" end # Restore original buffering mode $stdout.sync = buffering Password.new( pw ) end # :stopdoc: # Determine whether next character should be a vowel or consonant. # def Password.get_vowel_or_consonant rand( 2 ) == 1 ? VOWEL : CONSONANT end # :startdoc: # Generate a memorable password of _length_ characters, using phonemes that # a human-being can easily remember. _flags_ is one or more of # Password::ONE_DIGIT and Password::ONE_CASE, logically # OR'ed together. For example: # # pw = Password.phonemic( 8, Password::ONE_DIGIT | Password::ONE_CASE ) # # This would generate an eight character password, containing a digit and an # upper-case letter, such as Ug2shoth. # # This method was inspired by the # pwgen[http://sourceforge.net/projects/pwgen/] tool, written by Theodore # Ts'o. # # Generated passwords may contain any of the characters in # Password::PASSWD_CHARS. # def Password.phonemic(length=8, flags=nil) pw = nil ph_flags = flags loop do pw = "" # Separate the flags integer into an array of individual flags feature_flags = [ flags & ONE_DIGIT, flags & ONE_CASE ] prev = [] first = true desired = Password.get_vowel_or_consonant # Get an Array of all of the phonemes phonemes = PHONEMES.keys.map { |ph| ph.to_s } nr_phonemes = phonemes.size while pw.length < length do # Get a random phoneme and its length phoneme = phonemes[ rand( nr_phonemes ) ] ph_len = phoneme.length # Get its flags as an Array ph_flags = PHONEMES[ phoneme.to_sym ] ph_flags = [ ph_flags & CONSONANT, ph_flags & VOWEL, ph_flags & DIPHTHONG, ph_flags & NOT_FIRST ] # Filter on the basic type of the next phoneme next if ph_flags.include? desired # Handle the NOT_FIRST flag next if first and ph_flags.include? NOT_FIRST # Don't allow a VOWEL followed a vowel/diphthong pair next if prev.include? VOWEL and ph_flags.include? VOWEL and ph_flags.include? DIPHTHONG # Don't allow us to go longer than the desired length next if ph_len > length - pw.length # We've found a phoneme that meets our criteria pw << phoneme # Handle ONE_CASE if feature_flags.include? ONE_CASE if (first or ph_flags.include? CONSONANT) and rand( 10 ) < 3 pw[-ph_len, 1] = pw[-ph_len, 1].upcase feature_flags.delete ONE_CASE end end # Is password already long enough? break if pw.length >= length # Handle ONE_DIGIT if feature_flags.include? ONE_DIGIT if ! first and rand( 10 ) < 3 pw << ( rand( 10 ) + ?0 ).chr feature_flags.delete ONE_DIGIT first = true prev = [] desired = Password.get_vowel_or_consonant next end end if desired == CONSONANT desired = VOWEL elsif prev.include? VOWEL or ph_flags.include? DIPHTHONG or rand(10) > 3 desired = CONSONANT else desired = VOWEL end prev = ph_flags first = false end # Try again break unless feature_flags.include? ONE_CASE or feature_flags.include? ONE_DIGIT end Password.new( pw ) end # Generate a random password of _length_ characters. Unlike the # Password.phonemic method, no attempt will be made to generate a memorable # password. Generated passwords may contain any of the characters in # Password::PASSWD_CHARS. # # def Password.random(length=8) pw = "" nr_chars = PASSWD_CHARS.size length.times { pw << PASSWD_CHARS[ rand( nr_chars ) ] } Password.new( pw ) end # An alternative to Password.random. It uses the /dev/urandom # device to generate passwords, returning +nil+ on systems that do not # implement the device. The passwords it generates may contain any of the # characters in Password::PASSWD_CHARS, plus the additional # characters + and /. # def Password.urandom(length=8) return nil unless File.chardev? '/dev/urandom' rand_data = nil File.open( "/dev/urandom" ) { |f| rand_data = f.read( length ) } # Base64 encode it Password.new( [ rand_data ].pack( 'm' )[ 0 .. length - 1 ] ) end # Encrypt a password using _type_ encryption. _salt_, if supplied, will be # used to perturb the encryption algorithm and should be chosen from the # Password::SALT_CHARS. If no salt is given, a randomly generated # salt will be used. # def crypt(type=DES, salt='') unless ( salt.split( // ) - SALT_CHARS.split( // ) ).empty? raise CryptError, 'bad salt' end salt = Password.random( type ? 2 : 8 ) if salt.empty? # (Linux glibc2 interprets a salt prefix of '$1$' as a call to use MD5 # instead of DES when calling crypt(3)) salt = '$1$' + salt if type == MD5 # Pass to crypt in class String (our parent class) crypt = super( salt ) # Raise an exception if MD5 was wanted, but result is not recognisable if type == MD5 && crypt !~ /^\$1\$/ raise CryptError, 'MD5 not implemented' end crypt end end # Display a phonemic password, if run directly. # if $0 == __FILE__ puts Password.phonemic end ruby-password-0.5.3/Changelog0000644000076400007640000006017310401645546015750 0ustar ianmacdianmacd? Changelog RCS file: /var/cvs/ruby-password/CHANGES,v Working file: CHANGES head: 1.10 branch: locks: strict access list: symbolic names: v0-5-3: 1.10 v0-5-2: 1.9 v0-5-1: 1.7 v0-5-0: 1.5 v0-4-1: 1.4 v0-4-0: 1.3 v0-3-0: 1.2 v0-2-0: 1.1 keyword substitution: kv total revisions: 10; selected revisions: 10 description: ---------------------------- revision 1.10 date: 2006/03/02 19:44:13; author: ianmacd; state: Exp; lines: +8 -2 Updated for 0.5.3. ---------------------------- revision 1.9 date: 2004/09/04 22:20:27; author: ianmacd; state: Exp; lines: +2 -2 - update to 0.5.2 ---------------------------- revision 1.8 date: 2004/09/04 22:16:47; author: ianmacd; state: Exp; lines: +9 -1 - updated to 0.5.2 ---------------------------- revision 1.7 date: 2004/04/13 00:02:04; author: ianmacd; state: Exp; lines: +3 -1 - one last change for 0.5.1 ---------------------------- revision 1.6 date: 2004/04/12 23:36:55; author: ianmacd; state: Exp; lines: +9 -1 - updated for 0.5.1 ---------------------------- revision 1.5 date: 2004/04/09 08:28:45; author: ianmacd; state: Exp; lines: +68 -1 - updated for 0.5.0 ---------------------------- revision 1.4 date: 2003/11/12 09:25:40; author: ianmacd; state: Exp; lines: +7 -1 - warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed ---------------------------- revision 1.3 date: 2003/06/11 06:43:58; author: ianmacd; state: Exp; lines: +13 -4 - update version to 0.4.0 ---------------------------- revision 1.2 date: 2002/10/03 05:46:10; author: ianmacd; state: Exp; lines: +21 -4 - updates for 0.3.0 ---------------------------- revision 1.1 date: 2002/09/18 07:36:43; author: ianmacd; state: Exp; - initial check-in ============================================================================= RCS file: /var/cvs/ruby-password/INSTALL,v Working file: INSTALL head: 1.3 branch: locks: strict access list: symbolic names: v0-5-3: 1.3 v0-5-2: 1.3 v0-5-1: 1.3 v0-5-0: 1.3 v0-4-1: 1.2 v0-4-0: 1.2 v0-3-0: 1.2 v0-2-0: 1.2 keyword substitution: kv total revisions: 3; selected revisions: 3 description: ---------------------------- revision 1.3 date: 2004/04/07 09:29:03; author: ianmacd; state: Exp; lines: +7 -11 - updated ---------------------------- revision 1.2 date: 2002/06/18 23:58:16; author: ianmacd; state: Exp; lines: +11 -1 - add piece on generating and installing documentation ---------------------------- revision 1.1 date: 2002/06/18 22:18:38; author: ianmacd; state: Exp; - first versions ============================================================================= RCS file: /var/cvs/ruby-password/README,v Working file: README head: 1.5 branch: locks: strict access list: symbolic names: v0-5-3: 1.5 v0-5-2: 1.5 v0-5-1: 1.5 v0-5-0: 1.5 v0-4-1: 1.3 v0-4-0: 1.3 v0-3-0: 1.3 v0-2-0: 1.3 keyword substitution: kv total revisions: 5; selected revisions: 5 description: ---------------------------- revision 1.5 date: 2004/04/07 09:42:48; author: ianmacd; state: Exp; lines: +8 -4 - updated ---------------------------- revision 1.4 date: 2004/04/07 09:25:51; author: ianmacd; state: Exp; lines: +5 -6 - updated ---------------------------- revision 1.3 date: 2002/06/19 06:26:19; author: ianmacd; state: Exp; lines: +6 -1 - add small section on target audience ---------------------------- revision 1.2 date: 2002/06/18 23:20:49; author: ianmacd; state: Exp; lines: +13 -1 - add section on licence ---------------------------- revision 1.1 date: 2002/06/18 22:18:38; author: ianmacd; state: Exp; - first versions ============================================================================= RCS file: /var/cvs/ruby-password/extconf.rb,v Working file: extconf.rb head: 1.13 branch: locks: strict access list: symbolic names: v0-5-3: 1.13 v0-5-2: 1.12 v0-5-1: 1.11 v0-5-0: 1.11 v0-4-1: 1.8 v0-4-0: 1.8 v0-3-0: 1.8 v0-2-0: 1.7 standard: 1.1.1.1 default: 1.1.1 keyword substitution: kv total revisions: 14; selected revisions: 14 description: ---------------------------- revision 1.13 date: 2006/03/02 17:35:06; author: ianmacd; state: Exp; lines: +2 -3 Cannot build with packer.h. Scrap it. ---------------------------- revision 1.12 date: 2004/09/04 01:46:24; author: ianmacd; state: Exp; lines: +2 -1 - add /var/cache/cracklib/cracklib_dict.pwd to search path for dictionaries (this is the location for Debian Linux systems) ---------------------------- revision 1.11 date: 2004/04/09 08:27:16; author: ianmacd; state: Exp; lines: +2 -2 - make rm recursive to get doc/ directory ---------------------------- revision 1.10 date: 2004/04/09 07:53:56; author: ianmacd; state: Exp; lines: +6 -1 - make a test target for running the unit tests ---------------------------- revision 1.9 date: 2004/04/08 09:17:53; author: ianmacd; state: Exp; lines: +5 -12 - update for RDoc documentation; RD docs are gone now ---------------------------- revision 1.8 date: 2002/09/20 05:05:55; author: ianmacd; state: Exp; lines: +28 -17 - portability enhancements from Akinori MUSHA ---------------------------- revision 1.7 date: 2002/06/19 00:29:52; author: ianmacd; state: Exp; lines: +4 -10 - no need to avoid linking against libruby - my Ruby was broken ---------------------------- revision 1.6 date: 2002/06/18 23:49:13; author: ianmacd; state: Exp; lines: +2 -5 - avoid append operation to add extra targets ---------------------------- revision 1.5 date: 2002/06/18 23:36:46; author: ianmacd; state: Exp; lines: +5 -6 - use in-place editing to get rid of $(RUBY_INSTALL_NAME) ---------------------------- revision 1.4 date: 2002/06/18 23:21:51; author: ianmacd; state: Exp; lines: +2 -2 - delete doc files when running extra-clean target ---------------------------- revision 1.3 date: 2002/06/18 23:05:13; author: ianmacd; state: Exp; lines: +9 -6 - this code to remove the reference to libruby actually works ---------------------------- revision 1.2 date: 2002/06/18 22:51:29; author: ianmacd; state: Exp; lines: +19 -2 - add some more Makefile targets - attempt in-place editing to remove $(RUBY_INSTALL_NAME) from LIBS, since that makes us link to libruby, which makes our binary unnecessarily large (unfortunately, this in-place edit doesn't work) ---------------------------- revision 1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; lines: +0 -0 - initial check-in ============================================================================= RCS file: /var/cvs/ruby-password/pwgen.1,v Working file: pwgen.1 head: 1.2 branch: locks: strict access list: symbolic names: v0-5-3: 1.2 v0-5-2: 1.2 v0-5-1: 1.2 v0-5-0: 1.1 keyword substitution: kv total revisions: 2; selected revisions: 2 description: ---------------------------- revision 1.2 date: 2004/04/13 00:01:07; author: ianmacd; state: Exp; lines: +5 -2 - document -v|--version ---------------------------- revision 1.1 date: 2004/04/08 09:02:20; author: ianmacd; state: Exp; - man page for pwgen ============================================================================= RCS file: /var/cvs/ruby-password/rbcrack.c,v Working file: rbcrack.c head: 1.20 branch: locks: strict access list: symbolic names: v0-5-3: 1.20 v0-5-2: 1.18 v0-5-1: 1.17 v0-5-0: 1.16 v0-4-1: 1.11 v0-4-0: 1.10 v0-3-0: 1.8 v0-2-0: 1.3 standard: 1.1.1.1 default: 1.1.1 keyword substitution: kv total revisions: 21; selected revisions: 21 description: ---------------------------- revision 1.20 date: 2006/03/02 19:41:44; author: ianmacd; state: Exp; lines: +3 -3 Update copyright messages. ---------------------------- revision 1.19 date: 2006/03/02 17:35:06; author: ianmacd; state: Exp; lines: +1 -6 Cannot build with packer.h. Scrap it. ---------------------------- revision 1.18 date: 2004/09/04 22:20:27; author: ianmacd; state: Exp; lines: +2 -2 - update to 0.5.2 ---------------------------- revision 1.17 date: 2004/04/12 23:53:07; author: ianmacd; state: Exp; lines: +2 -2 - bumped to version 0.5.1 ---------------------------- revision 1.16 date: 2004/04/07 09:00:00; author: ianmacd; state: Exp; lines: +15 -2 - document Password#check ---------------------------- revision 1.15 date: 2004/04/06 10:15:31; author: ianmacd; state: Exp; lines: +45 -43 - run through indent ---------------------------- revision 1.14 date: 2004/04/06 10:13:52; author: ianmacd; state: Exp; lines: +1 -6 - don't define Password::VERSION here. Define it in password.rb instead ---------------------------- revision 1.13 date: 2004/04/06 10:09:54; author: ianmacd; state: Exp; lines: +7 -12 - rename BadDictionary exception to DictionaryError and make it a subclass of StandardError instead of RuntimeError - make WeakPassword exception a subclass of StandardError instead of RuntimeError ---------------------------- revision 1.12 date: 2004/04/06 09:40:17; author: ianmacd; state: Exp; lines: +4 -17 - remove passwd_init (Password#initialize) from here, as it's now implicitly done in password.rb, by having the Password class be a subclass of String. - bump version to 0.5.0 ---------------------------- revision 1.11 date: 2003/11/12 09:25:40; author: ianmacd; state: Exp; lines: +5 -3 - warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed ---------------------------- revision 1.10 date: 2003/06/11 06:43:58; author: ianmacd; state: Exp; lines: +3 -3 - update version to 0.4.0 ---------------------------- revision 1.9 date: 2002/10/03 22:44:42; author: ianmacd; state: Exp; lines: +28 -4 - in passwd_check(), raise a Password:BadDictionary exception when the path to the crack dictionary is incorrect. ---------------------------- revision 1.8 date: 2002/10/03 05:19:51; author: ianmacd; state: Exp; lines: +19 -19 - dispense with Crack class; use only Password ---------------------------- revision 1.7 date: 2002/09/28 20:07:05; author: ianmacd; state: Exp; lines: +2 -2 - version number updates ---------------------------- revision 1.6 date: 2002/09/28 20:03:14; author: ianmacd; state: Exp; lines: +2 -2 - update version to 0.2.1 ---------------------------- revision 1.5 date: 2002/09/24 00:17:50; author: ianmacd; state: Exp; lines: +20 -2 - add GPL header ---------------------------- revision 1.4 date: 2002/09/20 05:05:55; author: ianmacd; state: Exp; lines: +9 -2 - portability enhancements from Akinori MUSHA ---------------------------- revision 1.3 date: 2002/09/18 07:45:57; author: ianmacd; state: Exp; lines: +2 -2 - update version number ---------------------------- revision 1.2 date: 2002/09/18 07:27:37; author: ianmacd; state: Exp; lines: +17 -6 - make Crack#check return true on success, raise exception on failure ---------------------------- revision 1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; lines: +0 -0 - initial check-in ============================================================================= RCS file: /var/cvs/ruby-password/ruby-password.spec,v Working file: ruby-password.spec head: 1.20 branch: locks: strict access list: symbolic names: v0-5-3: 1.20 v0-5-2: 1.19 v0-5-1: 1.18 v0-5-0: 1.16 v0-4-1: 1.14 v0-4-0: 1.13 v0-3-0: 1.10 v0-2-0: 1.6 keyword substitution: kv total revisions: 20; selected revisions: 20 description: ---------------------------- revision 1.20 date: 2006/03/02 19:44:13; author: ianmacd; state: Exp; lines: +6 -2 Updated for 0.5.3. ---------------------------- revision 1.19 date: 2004/09/04 22:20:27; author: ianmacd; state: Exp; lines: +8 -2 - update to 0.5.2 ---------------------------- revision 1.18 date: 2004/04/13 00:02:53; author: ianmacd; state: Exp; lines: +2 -1 - one last change to document ---------------------------- revision 1.17 date: 2004/04/12 23:38:44; author: ianmacd; state: Exp; lines: +7 -2 - updated version and changelog ---------------------------- revision 1.16 date: 2004/04/09 09:44:42; author: ianmacd; state: Exp; lines: +2 -2 - pwgen was installed with the wrong mode ---------------------------- revision 1.15 date: 2004/04/09 09:18:48; author: ianmacd; state: Exp; lines: +61 -16 - update version and changelog ---------------------------- revision 1.14 date: 2003/11/12 09:25:40; author: ianmacd; state: Exp; lines: +6 -2 - warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed ---------------------------- revision 1.13 date: 2003/06/11 06:52:35; author: ianmacd; state: Exp; lines: +8 -2 - determine version of Ruby to require at build time ---------------------------- revision 1.12 date: 2003/06/11 06:43:58; author: ianmacd; state: Exp; lines: +12 -5 - update version to 0.4.0 ---------------------------- revision 1.11 date: 2003/03/29 22:01:42; author: ianmacd; state: Exp; lines: +3 -3 - fix a gsub for 1.8 ---------------------------- revision 1.10 date: 2002/10/03 06:03:21; author: ianmacd; state: Exp; lines: +2 -2 - no TODO file ---------------------------- revision 1.9 date: 2002/10/03 05:48:59; author: ianmacd; state: Exp; lines: +10 -4 - update version and changelog ---------------------------- revision 1.8 date: 2002/09/28 20:09:21; author: ianmacd; state: Exp; lines: +2 -2 - typo in date ---------------------------- revision 1.7 date: 2002/09/28 20:07:05; author: ianmacd; state: Exp; lines: +6 -2 - version number updates ---------------------------- revision 1.6 date: 2002/09/18 07:39:30; author: ianmacd; state: Exp; lines: +9 -4 - updated version and changelog ---------------------------- revision 1.5 date: 2002/07/11 05:37:19; author: ianmacd; state: Exp; lines: +7 -2 - update release to 0.1.1 ---------------------------- revision 1.4 date: 2002/06/19 00:29:52; author: ianmacd; state: Exp; lines: +1 -2 - no need to avoid linking against libruby - my Ruby was broken ---------------------------- revision 1.3 date: 2002/06/19 00:03:30; author: ianmacd; state: Exp; lines: +2 -2 - don't bother making docs; we'll just add them to the tar file ---------------------------- revision 1.2 date: 2002/06/19 00:01:26; author: ianmacd; state: Exp; lines: +6 -3 - package documentation as well ---------------------------- revision 1.1 date: 2002/06/18 09:21:28; author: ianmacd; state: Exp; - initial check-in of .spec file ============================================================================= RCS file: /var/cvs/ruby-password/example/example.rb,v Working file: example/example.rb head: 1.7 branch: locks: strict access list: symbolic names: v0-5-3: 1.7 v0-5-2: 1.7 v0-5-1: 1.7 v0-5-0: 1.7 v0-4-1: 1.6 v0-4-0: 1.6 v0-3-0: 1.6 v0-2-0: 1.3 standard: 1.1.1.1 default: 1.1.1 keyword substitution: kv total revisions: 8; selected revisions: 8 description: ---------------------------- revision 1.7 date: 2004/04/07 09:49:06; author: ianmacd; state: Exp; lines: +9 -11 - no longer need to call Password.new on strings fetched with Password.get and Password.getc. ---------------------------- revision 1.6 date: 2002/10/03 05:54:35; author: ianmacd; state: Exp; lines: +3 -3 - return Password::WeakPassword on weak password ---------------------------- revision 1.5 date: 2002/09/24 00:29:20; author: ianmacd; state: Exp; lines: +17 -1 - add GPL header ---------------------------- revision 1.4 date: 2002/09/20 00:39:50; author: ianmacd; state: Exp; lines: +6 -1 - don't reask for password with Password.get if password with Password.getc fails ---------------------------- revision 1.3 date: 2002/09/18 07:23:57; author: ianmacd; state: Exp; lines: +12 -13 - modifications in line with changes to Password#check ---------------------------- revision 1.2 date: 2002/06/18 23:21:27; author: ianmacd; state: Exp; lines: +2 -2 - use MD5 on Linux, otherwise DES ---------------------------- revision 1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; lines: +0 -0 - initial check-in ============================================================================= RCS file: /var/cvs/ruby-password/example/pwgen,v Working file: example/pwgen head: 1.3 branch: locks: strict access list: symbolic names: v0-5-3: 1.3 v0-5-2: 1.3 v0-5-1: 1.2 v0-5-0: 1.1 keyword substitution: kv total revisions: 3; selected revisions: 3 description: ---------------------------- revision 1.3 date: 2004/09/04 22:20:27; author: ianmacd; state: Exp; lines: +2 -2 - update to 0.5.2 ---------------------------- revision 1.2 date: 2004/04/12 23:59:30; author: ianmacd; state: Exp; lines: +8 -3 - add a -v|--version option ---------------------------- revision 1.1 date: 2004/04/08 08:47:57; author: ianmacd; state: Exp; - Ruby version of Ted Ts'o's pwgen program ============================================================================= RCS file: /var/cvs/ruby-password/lib/password.rb,v Working file: lib/password.rb head: 1.24 branch: locks: strict access list: symbolic names: v0-5-3: 1.24 v0-5-2: 1.22 v0-5-1: 1.21 v0-5-0: 1.19 v0-4-1: 1.13 v0-4-0: 1.12 v0-3-0: 1.9 v0-2-0: 1.6 standard: 1.1.1.1 default: 1.1.1 keyword substitution: kv total revisions: 25; selected revisions: 25 description: ---------------------------- revision 1.24 date: 2006/03/02 19:42:33; author: ianmacd; state: Exp; lines: +2 -2 Update to 0.5.3. ---------------------------- revision 1.23 date: 2006/03/02 19:41:44; author: ianmacd; state: Exp; lines: +3 -3 Update copyright messages. ---------------------------- revision 1.22 date: 2004/09/04 22:20:27; author: ianmacd; state: Exp; lines: +3 -3 - update to 0.5.2 ---------------------------- revision 1.21 date: 2004/04/12 23:53:07; author: ianmacd; state: Exp; lines: +3 -3 - bumped to version 0.5.1 ---------------------------- revision 1.20 date: 2004/04/12 08:49:08; author: ianmacd; state: Exp; lines: +4 -3 - ensure that Password.get does not fail when $stdin reaches EOF with no input. ---------------------------- revision 1.19 date: 2004/04/08 09:48:38; author: ianmacd; state: Exp; lines: +21 -8 - Password.get will now detect whether STDIN is connected to a tty. If not, no password prompt is displayed and no attempt will be made to manipulate terminal echo. - Running password.rb directly will now result in a call to Password.phonemic and the display of the password returned. ---------------------------- revision 1.18 date: 2004/04/07 09:03:14; author: ianmacd; state: Exp; lines: +39 -107 - Remove old RD documentation. - Bump version to 0.5.0. - Improve RDoc documentation with examples. - Duplicate exception definitions for DictionaryError and WeakPassword from rbcrack.c, so that they can be properly documented here. - Fixed a reference to non-existent local variable 'output', which should have been 'crypt'. ---------------------------- revision 1.17 date: 2004/04/07 07:55:56; author: ianmacd; state: Exp; lines: +68 -43 - Password::VERSION is now defined here, rather than in rbcrack.c. - Make Password class a subclass of String. - CryptError is now Password::CryptError and is a subclass of StandardError, not RuntimeError. - VALID_CHARS has been renamed PASSWD_CHARS. - A new constant, SALT_CHARS, lists the characters valid as salt characters when invoking #crypt. - Password.getc now returns a Password, not a String. - Password.phonemic now returns a Password, not a String. - Password.random now returns a Password, not a String. - Password.urandom now returns a Password, not a String. - Password::CryptError is now raised if a salt passed to #crypt contains a bad character. ---------------------------- revision 1.16 date: 2004/04/06 08:18:56; author: ianmacd; state: Exp; lines: +112 -96 - Shuffle things around a bit. ---------------------------- revision 1.15 date: 2004/04/06 07:58:45; author: ianmacd; state: Exp; lines: +75 -23 - Improve RDoc documentation - Alter Password.get and Password.getc so that the prompt is passed in its entirety when required. We no longer append ': ' to it, so that completely null prompts are now possible. ---------------------------- revision 1.14 date: 2004/04/05 02:44:37; author: ianmacd; state: Exp; lines: +198 -8 - new class method, Password.phonemic, generates phonemic passwords (code inspired by Ted Ts'o's pwgen program: http://sourceforge.net/projects/pwgen/). This uses some new constants and another class method, Password.get_vowel_or_consonant - rename Password.random to Password.urandom for historical purposes - new Password.random implementation does not rely on /dev/urandom, and so is portable. ---------------------------- revision 1.13 date: 2003/11/12 09:25:40; author: ianmacd; state: Exp; lines: +3 -3 - warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed ---------------------------- revision 1.12 date: 2003/06/11 06:43:58; author: ianmacd; state: Exp; lines: +3 -3 - update version to 0.4.0 ---------------------------- revision 1.11 date: 2003/06/11 00:17:28; author: ianmacd; state: Exp; lines: +12 -3 - in Password.getc, we need to turn off line buffering for Ruby 1.8, or the password prompt may not appear ---------------------------- revision 1.10 date: 2002/10/03 22:47:01; author: ianmacd; state: Exp; lines: +5 -4 - documentation changes to indicate that a Password::BadDictionary exception is now raised when a bad dictionary path is passed to Password#check ---------------------------- revision 1.9 date: 2002/10/03 05:27:02; author: ianmacd; state: Exp; lines: +6 -14 - with the Crack class gone, Password is now a direct subclass of String - the Password.initialize and Password#check methods are no longer needed here, since the ones in rbcrack.c now pertain to the Password class - Password#check now raises a Password::WeakPassword exception if the password is weak, not a Crack::WeakPassword exception ---------------------------- revision 1.8 date: 2002/09/28 20:07:05; author: ianmacd; state: Exp; lines: +3 -3 - version number updates ---------------------------- revision 1.7 date: 2002/09/24 18:23:07; author: ianmacd; state: Exp; lines: +7 -6 - format GNU message for man page ---------------------------- revision 1.6 date: 2002/09/18 07:22:55; author: ianmacd; state: Exp; lines: +11 -11 - Password#check now returns true on success and raises a Crack::WeakPassword exception on failure. ---------------------------- revision 1.5 date: 2002/07/11 05:20:09; author: ianmacd; state: Exp; lines: +3 -3 - update version to 0.1.1 ---------------------------- revision 1.4 date: 2002/07/10 04:02:02; author: ianmacd; state: Exp; lines: +3 -3 - default to assigning a null string when Password.new is called, to avoid this having to be passed by the user ---------------------------- revision 1.3 date: 2002/07/09 18:53:07; author: ianmacd; state: Exp; lines: +6 -6 - Password.get now returns an instance of Password, not String ---------------------------- revision 1.2 date: 2002/06/18 22:19:47; author: ianmacd; state: Exp; lines: +95 -11 - added a lot of embedded documentation, renamed some variables for clarity, and performed some very minor code clean-up ---------------------------- revision 1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2002/06/18 08:26:46; author: ianmacd; state: Exp; lines: +0 -0 - initial check-in ============================================================================= RCS file: /var/cvs/ruby-password/test/tc_password.rb,v Working file: test/tc_password.rb head: 1.3 branch: locks: strict access list: symbolic names: v0-5-3: 1.3 v0-5-2: 1.3 v0-5-1: 1.3 v0-5-0: 1.2 keyword substitution: kv total revisions: 3; selected revisions: 3 description: ---------------------------- revision 1.3 date: 2004/04/12 08:50:06; author: ianmacd; state: Exp; lines: +7 -2 - add a test for null $stdin ---------------------------- revision 1.2 date: 2004/04/09 07:21:49; author: ianmacd; state: Exp; lines: +2 -2 - modify path to make sure crack.so gets found before installation ---------------------------- revision 1.1 date: 2004/04/07 09:19:18; author: ianmacd; state: Exp; - initial set of unit tests ============================================================================= ruby-password-0.5.3/CHANGES0000644000076400007640000001055610401645415015124 0ustar ianmacdianmacd$Id: CHANGES,v 1.10 2006/03/02 19:44:13 ianmacd Exp $ 0.5.3 ----- No functional changes. The build no longer tries to use packer.h if available. crack.h will always be sought and used. 0.5.2 ----- No functional changes. The build environment was modified to search for the system dictionary in the additional location of /var/cache/cracklib/cracklib_dict.pwd, which is where it is on Debian Linux. 0.5.1 ----- Password.get would throw an exception in the unlikely event that STDIN reached EOF without any input. Thanks to Will Drewry for pointing this out. pwgen now supports a -v or --version switch. 0.5.0 ----- This is a major update. The user-visible changes between this version and the previous, 0.4.1, are as follows: A new example program, pwgen, has been added, complete with man page. Ted Ts'o's C program of the same name inspired this Ruby version. The man page is also adapted from his. A new class method, Password.phonemic, generates phonemic passwords. This, too, was inspired by Ted Ts'o's work on pwgen. As its second parameter, it can take zero or more new constants, logically OR'ed together. Available constants are Password::ONE_DIGIT and Password::ONE_CASE. The former specifies that the generated password should contain at least one digit, whilst the latter specifies that the password should contain at least one capital letter. The old Password.random method has been renamed Password.urandom and replaced by a new Password.random that does not depend on /dev/urandom, making it much more portable. Password.urandom will return nil on platforms that do not implement the /dev/urandom device. Password.get will now detect whether STDIN is connected to a tty. If not, no password prompt is displayed and no attempt will be made to manipulate terminal echo. The prompt parameter to Password.get and Password.getc must now be passed in its entirety. Previously, the string ': ' would be automatically appended to the user-supplied prompt, but this behaviour has been changed in order to accommodate null prompts. The default string for the prompt parameter has been changed accordingly. Running password.rb directly will now result in a call to Password.phonemic and the display of the resulting password. The Password::BadDictionary exception has been renamed Password::DictionaryError and made a subclass of StandardError instead of RuntimeError. The CryptError exception has been moved to Password::CryptError and is now a subclass of StandardError instead of RuntimeError. A new constant, PASSWD_CHARS, gives the list of characters from which automatically generated passwords will be chosen. Note that Password.urandom will use the additional characters '+' and '/'. A new constant, SALT_CHARS, gives the list of characters valid as salt characters when invoking Password#crypt. Password.getc now returns an instance of Password, not String. Password.random now returns a Password, not a String. A Password::CryptError exception is now raised if the salt passed to Password#crypt contains a bad character. RDoc documentation has been added. The INSTALL file explains how to build it. The RD documentation has been removed in favour of the RDoc documentation. 0.4.1 ----- Use of the rb_enable_super() function caused a warning in Ruby 1.8.x. This has now been fixed. 0.4.0 ----- When a bad dictionary path is provided to Password#check, a Password::BadDictionary exception is now raised. Turn off Ruby buffering for Password.getc, as this resulted in the prompt not being displayed when called by Ruby 1.8. 0.3.0 ----- The Crack class is gone and Password is now a direct subclass of String. If you were previously creating Crack objects and calling their methods, you can now no longer do this (and there really never was a good reason to do that, anyway). As a result of this change, Password#check now raises a Password::WeakPassword exception if the password is weak, not a Crack::WeakPassword exception. 0.2.1 ----- No new features. The only changes are portability enhancements to the build system. 0.2.0 ----- Password#check no longer returns an empty string on success and a string describing the nature of the password weakness on failure. Instead, it returns true on success and raises a Crack::WeakPassword exception on failure. 0.1.1 ----- Password.get now returns an instance of Password, not String. Password.new now defaults to assigning a null string. ruby-password-0.5.3/COPYING0000644000076400007640000004311007133036363015160 0ustar ianmacdianmacd GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ruby-password-0.5.3/extconf.rb0000644000076400007640000000224210401626312016110 0ustar ianmacdianmacd# extconf for Ruby/Password # # $Id: extconf.rb,v 1.13 2006/03/02 17:35:06 ianmacd Exp $ require 'mkmf' search_dicts = %w( /usr/local/lib/pw_dict.pwd /usr/lib/pw_dict.pwd /opt/lib/pw_dict.pwd /usr/local/lib/cracklib_dict.pwd /usr/lib/cracklib_dict.pwd /opt/lib/cracklib_dict.pwd /var/cache/cracklib/cracklib_dict.pwd ) if dict = with_config('crack-dict') search_dicts.unshift(dict) end crack_dict = nil # find the crack dictionary print "checking for cracklib dictionary... " search_dicts.each do |dict| # create a header file pointing to the crack dictionary if File.exist?(dict) puts dict crack_dict = dict.sub(/\.pwd/, '') break end end if crack_dict.nil? puts "no\nCouldn't find a cracklib dictionary on this system" exit 1 end hfile = File.new("rbcrack.h", 'w') hfile.printf("#define CRACK_DICT \"%s\"\n", crack_dict) hfile.close have_header('crack.h') && have_library('crack', 'FascistCheck') or exit 1 create_makefile('crack') File.open('Makefile', 'a') do |f| f.print < BuildRoot: /var/tmp/%{name}-%{version} BuildRequires: ruby, cracklib, cracklib-dicts Requires: ruby-termios, cracklib, cracklib-dicts %define ruby18 %( [ `ruby -r rbconfig -e 'print Config::CONFIG["MAJOR"], ".", Config::CONFIG["MINOR"]'` = '1.8' ] && echo 1 || echo 0 ) # build documentation if we have rdoc on the build system %define rdoc %( type rdoc > /dev/null && echo 1 || echo 0 ) %if %{ruby18} Requires: ruby >= 1.8.0 %else Requires: ruby >= 1.6.0 %endif %description Ruby/Password is a suite of password handling methods for Ruby. It supports the manual entry of passwords from the keyboard in both buffered and unbuffered modes, password strength checking, random password generation, phonemic password generation (for easy memorisation by human-beings) and the encryption of passwords. %prep %setup %build ruby extconf.rb make %clean rm -rf $RPM_BUILD_ROOT %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install install -d $RPM_BUILD_ROOT%{_mandir}/man1 install pwgen.1 $RPM_BUILD_ROOT%{_mandir}/man1 gzip -9 $RPM_BUILD_ROOT%{_mandir}/man1/pwgen.1 install -d $RPM_BUILD_ROOT%{_bindir} install -m755 example/pwgen $RPM_BUILD_ROOT%{_bindir} %if %{rdoc} rdocpath=`ruby -rrdoc/ri/ri_paths -e 'puts RI::Paths::PATH[1] || RI::Paths::PATH[0]'` rdoc -r -o $RPM_BUILD_ROOT$rdocpath -x CVS *.c lib rm $RPM_BUILD_ROOT$rdocpath/created.rid %endif find $RPM_BUILD_ROOT -type f -print | \ ruby -pe 'sub(%r(^'$RPM_BUILD_ROOT'), "")' > %{name}-%{version}-filelist %if %{rdoc} echo '%%docdir' $rdocpath >> %{name}-%{version}-filelist %endif find $RPM_BUILD_ROOT -type f -print | \ ruby -pe 'sub(%r(^'$RPM_BUILD_ROOT'), "")' > %{name}-%{version}-filelist %files -f %{name}-%{version}-filelist %defattr(-,root,root) %doc CHANGES COPYING INSTALL README %doc example/example.rb %changelog * Thu Mar 2 2006 Ian Macdonald 0.5.3-1 - 0.5.3 - Build environment no longer uses packer.h if available. - Package RDoc documentation in form usable by ri, rather than in HTML. * Sat Sep 4 2004 Ian Macdonald 0.5.2-1 - 0.5.2 - Build environment modified to search for the system dictionary in the additional location of /var/cache/cracklib/cracklib_dict.pwd, which is where it is on Debian Linux. * Mon Apr 12 2004 Ian Macdonald 0.5.1-1 - 0.5.1 - Password.get would throw an exception in the unlikely event that STDIN reached EOF without any input. - pwgen now supports a -v or --version flag. * Fri Apr 9 2004 Ian Macdonald 0.5.0-1 - 0.5.0 - A new example program, pwgen, has been added, complete with man page. - A new class method, Password.phonemic, generates phonemic passwords. - The old Password.random method has been renamed Password.urandom and replaced by a new, portable Password.random. - Password.get will now detect whether STDIN is connected to a tty. If not, no password prompt is displayed and no attempt will be made to manipulate terminal echo. - The prompt parameter to Password.get and Password.getc must now be passed in its entirety. - Running password.rb directly will now result in a call to Password.phonemic and the display of the resulting password. - The Password::BadDictionary exception has been renamed Password::DictionaryError and made a subclass of StandardError instead of RuntimeError. - The CryptError exception has been moved to Password::CryptError and is now a subclass of StandardError instead of RuntimeError. - A new constant, PASSWD_CHARS, gives the list of characters from which automatically generated passwords will be chosen. Note that Password.urandom will use the additional characters '+' and '/'. - A new constant, SALT_CHARS, gives the list of characters valid as salt characters when invoking Password#crypt. - Password.getc and Password.random now return an instance of Password, not String. - A Password::CryptError exception is now raised if the salt passed to Password#crypt contains a bad character. - RDoc documentation has been added. - The old RD documentation has been removed. - Unit-tests are now included with the software to verify its correct working. * Wed Nov 12 2003 Ian Macdonald 0.4.1-1 - 0.4.1 - Warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed * Wed Jun 10 2003 Ian Macdonald 0.4.0-1 - 0.4.0 - When a bad dictionary path is provided to Password#check, a Password::BadDictionary exception is now raised - Turn off Ruby buffering for Password.getc, as this resulted in the prompt not being displayed when called by Ruby 1.8 * Wed Oct 2 2002 Ian Macdonald 0.3.0-1 - 0.3.0 - Password#check now raises a Password::WeakPassword exception when provided with a weak password * Sat Sep 28 2002 Ian Macdonald 0.2.1-1 - 0.2.1 - Portability enhancements from Akinori MUSHA * Wed Sep 18 2002 Ian Macdonald 0.2.0-1 - 0.2.0 - Password#check now returns true on success, and raises a Crack::WeakPassword exception on failure * Tue Jun 18 2002 Ian Macdonald 0.1.1-1 - 0.1.1 - Password.get now returns an instance of Password, not String - Password.new now defaults to assigning a null string * Tue Jun 18 2002 Ian Macdonald 0.1.0-1 - 0.1.0 ruby-password-0.5.3/rbcrack.c0000644000076400007640000000636410401645170015704 0ustar ianmacdianmacd/* rbcrack.c - a Ruby interface to CrackLib * * $Id: rbcrack.c,v 1.20 2006/03/02 19:41:44 ianmacd Exp $ * * Version : 0.5.3 * Author : Ian Macdonald * * Copyright (C) 2002-2006 Ian Macdonald * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include "rbcrack.h" VALUE ePassword_DictionaryError; VALUE ePassword_WeakPassword; /* check(dict=nil) * * This interfaces to LibCrack to check the strength of the password. If * _dict_ is given, it is the path to the CrackLib dictionary, minus the * file's extension. For example, if the dictionary is located at * /usr/lib/cracklib_dict.pwd, _dict_ would be * /usr/lib/cracklib_dict. If it is not given, the dictionary found * at build time will be used. * * If a path is given that does not lead to a legible dictionary, a * Password::DictionaryError exception is raised. On success, +true+ is * returned. On failure, a Password::WeakPassword exception is raised. */ static VALUE passwd_check(VALUE self, VALUE args) { VALUE dict; char *objection; char *buffer; /* pop the one and only argument we may have been passed */ dict = rb_ary_pop(args); if (dict == Qnil || strcmp(STR2CSTR(dict), "") == 0) { /* no argument passed, so use default location from rbcrack.h */ dict = rb_str_new2(CRACK_DICT); } else { buffer = malloc(strlen(STR2CSTR(dict)) + 8); strcpy(buffer, STR2CSTR(dict)); strcat(buffer, ".pwd"); if (access(buffer, R_OK) != 0) { free(buffer); rb_raise(ePassword_DictionaryError, "%s", strerror(errno)); } free(buffer); } /* perform check on password */ objection = FascistCheck(STR2CSTR(self), STR2CSTR(dict)); /* return true on success; raise an exception otherwise */ if (objection) { rb_raise(ePassword_WeakPassword, "%s", objection); } else { return Qtrue; } } /* initialize this class */ void Init_crack() { VALUE cPassword; /* define the Password class */ cPassword = rb_define_class("Password", rb_cString); /* define the Password::DictionaryError exception */ ePassword_DictionaryError = rb_define_class_under(cPassword, "DictionaryError", rb_eStandardError); /* define the Password::WeakPassword exception */ ePassword_WeakPassword = rb_define_class_under(cPassword, "WeakPassword", rb_eStandardError); /* define the Password.check method */ rb_define_method(cPassword, "check", passwd_check, -2); return; } ruby-password-0.5.3/pwgen.10000644000076400007640000000457410036626703015341 0ustar ianmacdianmacd.\" $Id: pwgen.1,v 1.2 2004/04/13 00:01:07 ianmacd Exp $ .\" .TH PWGEN 1 "April 2004" "pwgen" .SH NAME pwgen \- generate pronounceable passwords .SH SYNOPSIS .B pwgen [ .I OPTION ] [ .I password_length ] [ .I number_passwords ] .SH DESCRIPTION .B pwgen generates passwords which are designed to be easily memorised by humans, whilst being as secure as possible. .PP The .B pwgen program is designed to be used both interactively, and in shell scripts. Hence, its default behaviour differs depending on whether the standard output is a tty device or a pipe to another program. Used interactively, .B pwgen will display a screenful of passwords, allowing the user to pick a single password, and then quickly erase the screen. This prevents someone from being able to "shoulder-surf" the user's chosen password. .PP When standard output is not a tty, .B pwgen will only generate one password, as this tends to be much more convenient for shell scripts. This also assures that .B pwgen is compatible with other versions of this program. .B .SH OPTIONS .TP .B \-c, --capitalise, --capitalize Include at least one capital letter in the password. This is the default if the standard output is a tty device. .TP .B \-C Print the generated passwords in columns. This is the default if the standard output is a tty device. .TP .B \-n, --numerals Include at least one number in the password. This is the default if the standard output is a tty device. .TP .B \--no-numerals Don't include a number in the generated passwords. .TP .B \--no-capitalise, --no-capitalize Don't bother to include any capital letters in the generated passwords. .TP .B \-s, --secure Generate completely random, hard-to-memorise paswords. These should only be used for machine passwords, since otherwise it's almost guaranteed that users will simply write the password on a piece of paper taped to the monitor... .TP .B \-v, --version Display the program version and exit. .TP .B \-h, --help Display a help message and exit. .TP .B \-1 Print the generated passwords one per line. .SH AUTHOR This version of .B pwgen was written by Ian Macdonald . It is modelled after a program originally written by Brandon S. Allbery and then later extensively modified by Olaf Titz, Jim Lynch, and others. It was later rewritten from scratch by Theodore Ts'o. This man page is lifted largely from Theodore Ts'o's man page. .SH SEE ALSO .BR passwd (1) ruby-password-0.5.3/test/0000755000076400007640000000000010401645042015075 5ustar ianmacdianmacdruby-password-0.5.3/test/tc_password.rb0000755000076400007640000000461210036454076017771 0ustar ianmacdianmacd#!/usr/bin/ruby -w # # $Id: tc_password.rb,v 1.3 2004/04/12 08:50:06 ianmacd Exp $ $: << File.dirname(__FILE__) + "/.." << File.dirname(__FILE__) + "/../lib" require 'test/unit' require 'password' TIMES = 1000 LENGTH = 32 class TC_PasswordTest < Test::Unit::TestCase def test_check # Check for a weak password. pw = Password.new( 'foo' ) assert_raises( Password::WeakPassword ) { pw.check } # Check for a good password. pw = Password.new( 'G@7flAxg' ) assert_nothing_raised { pw.check } # Check for an exception on bad dictionary path. assert_raises( Password::DictionaryError ) { pw.check( '/tmp/nodict' ) } end def test_phonemic TIMES.times do |t| pw = Password.phonemic( LENGTH ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_phonemic_one_case TIMES.times do |t| pw = Password.phonemic( LENGTH, Password::ONE_CASE ) assert( pw =~ /[A-Z]/, "#{pw} has no upper-case letter" ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_phonemic_one_digit TIMES.times do |t| pw = Password.phonemic( LENGTH, Password::ONE_DIGIT ) assert( pw =~ /[0-9]/, "#{pw} has no digit" ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_phonemic_one_case_one_digit TIMES.times do |t| pw = Password.phonemic( LENGTH, Password::ONE_CASE | Password::ONE_DIGIT ) assert( pw =~ /[A-Z]/, "#{pw} has no upper-case letter" ) assert( pw =~ /[0-9]/, "#{pw} has no digit" ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_random TIMES.times do |t| pw = Password.random( LENGTH ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_urandom TIMES.times do |t| pw = Password.urandom( LENGTH ) assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" ) end end def test_crypt pw = Password.random( LENGTH ) assert_nothing_raised { pw.crypt( Password::DES ) } assert_nothing_raised { pw.crypt( Password::MD5 ) } assert_raises( Password::CryptError ) { pw.crypt( Password::DES, '@*' ) } end def test_null_stdin $stdin.reopen( File.new( '/dev/null' ) ) assert_nothing_raised { Password.get } end end