ruby-password 0.15.5

Sign up to get free protection for your applications and to get access to all the features.
data/pwgen.1 ADDED
@@ -0,0 +1,83 @@
1
+ .\" $Id: pwgen.1,v 1.2 2004/04/13 00:01:07 ianmacd Exp $
2
+ .\"
3
+ .TH PWGEN 1 "April 2004" "pwgen"
4
+ .SH NAME
5
+ pwgen \- generate pronounceable passwords
6
+ .SH SYNOPSIS
7
+ .B pwgen
8
+ [
9
+ .I OPTION
10
+ ]
11
+ [
12
+ .I password_length
13
+ ]
14
+ [
15
+ .I number_passwords
16
+ ]
17
+ .SH DESCRIPTION
18
+ .B pwgen
19
+ generates passwords which are designed to be easily memorised by humans,
20
+ whilst being as secure as possible.
21
+ .PP
22
+ The
23
+ .B pwgen
24
+ program is designed
25
+ to be used both interactively, and in shell scripts. Hence,
26
+ its default behaviour differs depending on whether the standard output
27
+ is a tty device or a pipe to another program. Used interactively,
28
+ .B pwgen
29
+ will display a screenful of passwords, allowing the user to pick a single
30
+ password, and then quickly erase the screen. This prevents someone from
31
+ being able to "shoulder-surf" the user's chosen password.
32
+ .PP
33
+ When standard output is not a tty,
34
+ .B pwgen
35
+ will only generate one password, as this tends to be much more convenient
36
+ for shell scripts. This also assures that
37
+ .B pwgen
38
+ is compatible with other versions of this program.
39
+ .B
40
+ .SH OPTIONS
41
+ .TP
42
+ .B \-c, --capitalise, --capitalize
43
+ Include at least one capital letter in the password. This is the default
44
+ if the standard output is a tty device.
45
+ .TP
46
+ .B \-C
47
+ Print the generated passwords in columns. This is the default if the
48
+ standard output is a tty device.
49
+ .TP
50
+ .B \-n, --numerals
51
+ Include at least one number in the password. This is the default
52
+ if the standard output is a tty device.
53
+ .TP
54
+ .B \--no-numerals
55
+ Don't include a number in the generated passwords.
56
+ .TP
57
+ .B \--no-capitalise, --no-capitalize
58
+ Don't bother to include any capital letters in the generated passwords.
59
+ .TP
60
+ .B \-s, --secure
61
+ Generate completely random, hard-to-memorise paswords. These should
62
+ only be used for machine passwords, since otherwise it's almost
63
+ guaranteed that users will simply write the password on a piece of
64
+ paper taped to the monitor...
65
+ .TP
66
+ .B \-v, --version
67
+ Display the program version and exit.
68
+ .TP
69
+ .B \-h, --help
70
+ Display a help message and exit.
71
+ .TP
72
+ .B \-1
73
+ Print the generated passwords one per line.
74
+ .SH AUTHOR
75
+ This version of
76
+ .B pwgen
77
+ was written by Ian Macdonald <ian@caliban.org>.
78
+ It is modelled after a program originally written by Brandon S. Allbery and
79
+ then later extensively modified by Olaf Titz, Jim Lynch, and others. It was
80
+ later rewritten from scratch by Theodore Ts'o. This man page is lifted largely
81
+ from Theodore Ts'o's man page.
82
+ .SH SEE ALSO
83
+ .BR passwd (1)
@@ -0,0 +1,113 @@
1
+ /* rbcrack.c - a Ruby interface to CrackLib
2
+ *
3
+ * $Id: rbcrack.c,v 1.20 2006/03/02 19:41:44 ianmacd Exp $
4
+ *
5
+ * Version : 0.5.3
6
+ * Author : Ian Macdonald <ian@caliban.org>
7
+ *
8
+ * Copyright (C) 2002-2006 Ian Macdonald
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, or (at your option)
13
+ * 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 Foundation,
22
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
+ */
24
+
25
+ #include <ruby.h>
26
+ #include <stdio.h>
27
+ #include <stdlib.h>
28
+ #include <string.h>
29
+ #include <unistd.h>
30
+ #include <errno.h>
31
+ #include <crack.h>
32
+
33
+ #include "rbcrack.h"
34
+
35
+
36
+ VALUE ePassword_DictionaryError;
37
+ VALUE ePassword_WeakPassword;
38
+
39
+
40
+ /* <b>check</b><em>(dict=nil)</em>
41
+ *
42
+ * This interfaces to LibCrack to check the strength of the password. If
43
+ * _dict_ is given, it is the path to the CrackLib dictionary, minus the
44
+ * file's extension. For example, if the dictionary is located at
45
+ * <tt>/usr/lib/cracklib_dict.pwd</tt>, _dict_ would be
46
+ * <tt>/usr/lib/cracklib_dict</tt>. If it is not given, the dictionary found
47
+ * at build time will be used.
48
+ *
49
+ * If a path is given that does not lead to a legible dictionary, a
50
+ * Password::DictionaryError exception is raised. On success, +true+ is
51
+ * returned. On failure, a Password::WeakPassword exception is raised.
52
+ */
53
+ static VALUE passwd_check(VALUE self, VALUE args)
54
+ {
55
+ VALUE dict;
56
+ char *objection;
57
+ char *buffer;
58
+
59
+ /* pop the one and only argument we may have been passed */
60
+ dict = rb_ary_pop(args);
61
+
62
+ if (dict == Qnil || strcmp(STR2CSTR(dict), "") == 0) {
63
+ /* no argument passed, so use default location from rbcrack.h */
64
+ dict = rb_str_new2(CRACK_DICT);
65
+ } else {
66
+ buffer = malloc(strlen(STR2CSTR(dict)) + 8);
67
+ strcpy(buffer, STR2CSTR(dict));
68
+ strcat(buffer, ".pwd");
69
+
70
+ if (access(buffer, R_OK) != 0) {
71
+ free(buffer);
72
+ rb_raise(ePassword_DictionaryError, "%s", strerror(errno));
73
+ }
74
+
75
+ free(buffer);
76
+
77
+ }
78
+
79
+ /* perform check on password */
80
+ objection = FascistCheck(STR2CSTR(self), STR2CSTR(dict));
81
+
82
+ /* return true on success; raise an exception otherwise */
83
+ if (objection) {
84
+ rb_raise(ePassword_WeakPassword, "%s", objection);
85
+ } else {
86
+ return Qtrue;
87
+ }
88
+
89
+ }
90
+
91
+ /* initialize this class */
92
+ void Init_cracklib()
93
+ {
94
+ VALUE cPassword;
95
+
96
+ /* define the Password class */
97
+ cPassword = rb_define_class("Password", rb_cString);
98
+
99
+ /* define the Password::DictionaryError exception */
100
+ ePassword_DictionaryError =
101
+ rb_define_class_under(cPassword, "DictionaryError",
102
+ rb_eStandardError);
103
+
104
+ /* define the Password::WeakPassword exception */
105
+ ePassword_WeakPassword =
106
+ rb_define_class_under(cPassword, "WeakPassword",
107
+ rb_eStandardError);
108
+
109
+ /* define the Password.check method */
110
+ rb_define_method(cPassword, "check", passwd_check, -2);
111
+
112
+ return;
113
+ }
@@ -0,0 +1,153 @@
1
+ # $Id: ruby-password.spec,v 1.21 2006/03/02 19:53:18 ianmacd Exp $
2
+ #
3
+
4
+ Summary: A password handling library for Ruby with interface to CrackLib
5
+ Name: ruby-password
6
+ Version: 0.5.3
7
+ Release: 1
8
+ License: GPL
9
+ Group: Applications/Ruby
10
+ Source: http://www.caliban.org/files/ruby/%{name}-%{version}.tar.gz
11
+ URL: http://www.caliban.org/ruby/
12
+ Packager: Ian Macdonald <ian@caliban.org>
13
+ BuildRoot: /var/tmp/%{name}-%{version}
14
+ BuildRequires: ruby, cracklib, cracklib-dicts
15
+ Requires: ruby-termios, cracklib, cracklib-dicts
16
+
17
+ %define ruby18 %( [ `ruby -r rbconfig -e 'print Config::CONFIG["MAJOR"], ".", Config::CONFIG["MINOR"]'` = '1.8' ] && echo 1 || echo 0 )
18
+
19
+ # build documentation if we have rdoc on the build system
20
+ %define rdoc %( type rdoc > /dev/null && echo 1 || echo 0 )
21
+
22
+ %if %{ruby18}
23
+ Requires: ruby >= 1.8.0
24
+ %else
25
+ Requires: ruby >= 1.6.0
26
+ %endif
27
+
28
+ %description
29
+ Ruby/Password is a suite of password handling methods for Ruby. It supports
30
+ the manual entry of passwords from the keyboard in both buffered and
31
+ unbuffered modes, password strength checking, random password generation,
32
+ phonemic password generation (for easy memorisation by human-beings) and the
33
+ encryption of passwords.
34
+
35
+ %prep
36
+ %setup
37
+
38
+ %build
39
+ ruby extconf.rb
40
+ make
41
+
42
+ %clean
43
+ rm -rf $RPM_BUILD_ROOT
44
+
45
+ %install
46
+ rm -rf $RPM_BUILD_ROOT
47
+ make DESTDIR=$RPM_BUILD_ROOT install
48
+ install -d $RPM_BUILD_ROOT%{_mandir}/man1
49
+ install pwgen.1 $RPM_BUILD_ROOT%{_mandir}/man1
50
+ gzip -9 $RPM_BUILD_ROOT%{_mandir}/man1/pwgen.1
51
+ install -d $RPM_BUILD_ROOT%{_bindir}
52
+ install -m755 example/pwgen $RPM_BUILD_ROOT%{_bindir}
53
+ %if %{rdoc}
54
+ rdocpath=`ruby -rrdoc/ri/ri_paths -e 'puts RI::Paths::PATH[1] ||
55
+ RI::Paths::PATH[0]'`
56
+ rdoc -r -o $RPM_BUILD_ROOT$rdocpath -x CVS *.c lib
57
+ rm $RPM_BUILD_ROOT$rdocpath/created.rid
58
+ %endif
59
+ find $RPM_BUILD_ROOT -type f -print | \
60
+ ruby -pe 'sub(%r(^'$RPM_BUILD_ROOT'), "")' > %{name}-%{version}-filelist
61
+ %if %{rdoc}
62
+ echo '%%docdir' $rdocpath >> %{name}-%{version}-filelist
63
+ %endif
64
+
65
+ find $RPM_BUILD_ROOT -type f -print | \
66
+ ruby -pe 'sub(%r(^'$RPM_BUILD_ROOT'), "")' > %{name}-%{version}-filelist
67
+
68
+ %files -f %{name}-%{version}-filelist
69
+ %defattr(-,root,root)
70
+ %doc CHANGES COPYING INSTALL README
71
+ %doc example/example.rb
72
+
73
+ %changelog
74
+ * Thu Mar 2 2006 Ian Macdonald <ian@caliban.org> 0.5.3-1
75
+ - 0.5.3
76
+ - Build environment no longer uses packer.h if available.
77
+ - Package RDoc documentation in form usable by ri, rather than in HTML.
78
+
79
+ * Sat Sep 4 2004 Ian Macdonald <ian@caliban.org> 0.5.2-1
80
+ - 0.5.2
81
+ - Build environment modified to search for the system dictionary in the
82
+ additional location of /var/cache/cracklib/cracklib_dict.pwd, which is where
83
+ it is on Debian Linux.
84
+
85
+ * Mon Apr 12 2004 Ian Macdonald <ian@caliban.org> 0.5.1-1
86
+ - 0.5.1
87
+ - Password.get would throw an exception in the unlikely event that STDIN
88
+ reached EOF without any input.
89
+ - pwgen now supports a -v or --version flag.
90
+
91
+ * Fri Apr 9 2004 Ian Macdonald <ian@caliban.org> 0.5.0-1
92
+ - 0.5.0
93
+ - A new example program, pwgen, has been added, complete with man page.
94
+ - A new class method, Password.phonemic, generates phonemic passwords.
95
+ - The old Password.random method has been renamed Password.urandom and
96
+ replaced by a new, portable Password.random.
97
+ - Password.get will now detect whether STDIN is connected to a tty. If not, no
98
+ password prompt is displayed and no attempt will be made to manipulate
99
+ terminal echo.
100
+ - The prompt parameter to Password.get and Password.getc must now be passed in
101
+ its entirety.
102
+ - Running password.rb directly will now result in a call to Password.phonemic
103
+ and the display of the resulting password.
104
+ - The Password::BadDictionary exception has been renamed
105
+ Password::DictionaryError and made a subclass of StandardError instead of
106
+ RuntimeError.
107
+ - The CryptError exception has been moved to Password::CryptError and is now a
108
+ subclass of StandardError instead of RuntimeError.
109
+ - A new constant, PASSWD_CHARS, gives the list of characters from which
110
+ automatically generated passwords will be chosen. Note that Password.urandom
111
+ will use the additional characters '+' and '/'.
112
+ - A new constant, SALT_CHARS, gives the list of characters valid as salt
113
+ characters when invoking Password#crypt.
114
+ - Password.getc and Password.random now return an instance of Password, not
115
+ String.
116
+ - A Password::CryptError exception is now raised if the salt passed to
117
+ Password#crypt contains a bad character.
118
+ - RDoc documentation has been added.
119
+ - The old RD documentation has been removed.
120
+ - Unit-tests are now included with the software to verify its correct working.
121
+
122
+ * Wed Nov 12 2003 Ian Macdonald <ian@caliban.org> 0.4.1-1
123
+ - 0.4.1
124
+ - Warning in Ruby 1.8.x caused by use of rb_enable_super() has been fixed
125
+
126
+ * Wed Jun 10 2003 Ian Macdonald <ian@caliban.org> 0.4.0-1
127
+ - 0.4.0
128
+ - When a bad dictionary path is provided to Password#check, a
129
+ Password::BadDictionary exception is now raised
130
+ - Turn off Ruby buffering for Password.getc, as this resulted in the prompt
131
+ not being displayed when called by Ruby 1.8
132
+
133
+ * Wed Oct 2 2002 Ian Macdonald <ian@caliban.org> 0.3.0-1
134
+ - 0.3.0
135
+ - Password#check now raises a Password::WeakPassword exception when provided
136
+ with a weak password
137
+
138
+ * Sat Sep 28 2002 Ian Macdonald <ian@caliban.org> 0.2.1-1
139
+ - 0.2.1
140
+ - Portability enhancements from Akinori MUSHA <knu@iDaemons.org>
141
+
142
+ * Wed Sep 18 2002 Ian Macdonald <ian@caliban.org> 0.2.0-1
143
+ - 0.2.0
144
+ - Password#check now returns true on success, and raises a Crack::WeakPassword
145
+ exception on failure
146
+
147
+ * Tue Jun 18 2002 Ian Macdonald <ian@caliban.org> 0.1.1-1
148
+ - 0.1.1
149
+ - Password.get now returns an instance of Password, not String
150
+ - Password.new now defaults to assigning a null string
151
+
152
+ * Tue Jun 18 2002 Ian Macdonald <ian@caliban.org> 0.1.0-1
153
+ - 0.1.0
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # $Id: tc_password.rb,v 1.3 2004/04/12 08:50:06 ianmacd Exp $
4
+
5
+ $: << File.dirname(__FILE__) + "/.." << File.dirname(__FILE__) + "/../lib"
6
+
7
+ require 'test/unit'
8
+ require 'password'
9
+
10
+
11
+ TIMES = 1000
12
+ LENGTH = 32
13
+
14
+
15
+ class TC_PasswordTest < Test::Unit::TestCase
16
+
17
+ def test_check
18
+ # Check for a weak password.
19
+ pw = Password.new( 'foo' )
20
+ assert_raises( Password::WeakPassword ) { pw.check }
21
+
22
+ # Check for a good password.
23
+ pw = Password.new( 'G@7flAxg' )
24
+ assert_nothing_raised { pw.check }
25
+
26
+ # Check for an exception on bad dictionary path.
27
+ assert_raises( Password::DictionaryError ) { pw.check( '/tmp/nodict' ) }
28
+ end
29
+
30
+ def test_phonemic
31
+ TIMES.times do |t|
32
+ pw = Password.phonemic( LENGTH )
33
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
34
+ end
35
+ end
36
+
37
+ def test_phonemic_one_case
38
+ TIMES.times do |t|
39
+ pw = Password.phonemic( LENGTH, Password::ONE_CASE )
40
+ assert( pw =~ /[A-Z]/, "#{pw} has no upper-case letter" )
41
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
42
+ end
43
+ end
44
+
45
+ def test_phonemic_one_digit
46
+ TIMES.times do |t|
47
+ pw = Password.phonemic( LENGTH, Password::ONE_DIGIT )
48
+ assert( pw =~ /[0-9]/, "#{pw} has no digit" )
49
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
50
+ end
51
+ end
52
+
53
+ def test_phonemic_one_case_one_digit
54
+ TIMES.times do |t|
55
+ pw = Password.phonemic( LENGTH, Password::ONE_CASE |
56
+ Password::ONE_DIGIT )
57
+ assert( pw =~ /[A-Z]/, "#{pw} has no upper-case letter" )
58
+ assert( pw =~ /[0-9]/, "#{pw} has no digit" )
59
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
60
+ end
61
+ end
62
+
63
+ def test_random
64
+ TIMES.times do |t|
65
+ pw = Password.random( LENGTH )
66
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
67
+ end
68
+ end
69
+
70
+ def test_urandom
71
+ TIMES.times do |t|
72
+ pw = Password.urandom( LENGTH )
73
+ assert( pw.length == LENGTH, "bad length: #{pw.length}, not #{LENGTH}" )
74
+ end
75
+ end
76
+
77
+ def test_crypt
78
+ pw = Password.random( LENGTH )
79
+ assert_nothing_raised { pw.crypt( Password::DES ) }
80
+ assert_nothing_raised { pw.crypt( Password::MD5 ) }
81
+ assert_raises( Password::CryptError ) { pw.crypt( Password::DES, '@*' ) }
82
+ end
83
+
84
+ def test_null_stdin
85
+ $stdin.reopen( File.new( '/dev/null' ) )
86
+ assert_nothing_raised { Password.get }
87
+ end
88
+
89
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-password
3
+ version: !ruby/object:Gem::Version
4
+ hash: 41
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 15
9
+ - 5
10
+ version: 0.15.5
11
+ platform: ruby
12
+ authors:
13
+ - Albert Lash
14
+ - Ian Macdonald
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-29 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: ruby-termios
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: |-
51
+ Ruby/Password is a suite of password handling methods for Ruby. It supports
52
+ the manual entry of passwords from the keyboard in both buffered and
53
+ unbuffered modes, password strength checking, random password generation,
54
+ phonemic password generation (for easy memorisation by human-beings) and the
55
+ encryption of passwords.
56
+ email: albert.lash@docunext.com
57
+ executables: []
58
+
59
+ extensions:
60
+ - extconf.rb
61
+ extra_rdoc_files:
62
+ - README
63
+ files:
64
+ - .gitignore
65
+ - CHANGES
66
+ - COPYING
67
+ - Changelog
68
+ - INSTALL
69
+ - README
70
+ - Rakefile
71
+ - VERSION
72
+ - example/example.rb
73
+ - example/pwgen
74
+ - extconf.rb
75
+ - lib/password.rb
76
+ - pwgen.1
77
+ - rbcrack.c
78
+ - ruby-password.spec
79
+ - test/tc_password.rb
80
+ has_rdoc: true
81
+ homepage: http://www.docunext.com/
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: A password handling library for Ruby with interface to CrackLib
114
+ test_files:
115
+ - test/tc_password.rb