1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=490146#10
--- a/lib/password.rb
+++ b/lib/password.rb
@@ -19,11 +19,6 @@
# 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.
@@ -164,6 +159,8 @@
# normal operations.
#
def Password.echo(on=true, masked=false)
+ require 'termios'
+
term = Termios::getattr( $stdin )
if on
@@ -183,6 +180,8 @@
# connected to a tty, no prompt will be displayed.
#
def Password.get(message="Password: ")
+ require 'termios'
+
begin
if $stdin.tty?
Password.echo false
@@ -206,6 +205,8 @@
# _mask_ to the terminal. There is no need to hit <b>[Enter]</b> at the end.
#
def Password.getc(message="Password: ", mask='*')
+ require 'termios'
+
# Save current buffering mode
buffering = $stdout.sync
@@ -401,6 +402,20 @@
#
def crypt(type=DES, salt='')
+ # Compatibility with String's crypt method.
+ # Really, salt should be the first argument here.
+ if (type.kind_of?(String) && salt == '')
+ salt = type
+ type = (type =~ /^\$1\$/ ? MD5 : DES)
+ end
+
+ # Compatibility with String's crypt method.
+ # Really, salt should be the first argument here.
+ if (type.kind_of?(String) && salt == '')
+ salt = type
+ type = (salt =~ /^\$1\$/ ? MD5 : DES)
+ end
+
unless ( salt.split( // ) - SALT_CHARS.split( // ) ).empty?
raise CryptError, 'bad salt'
end
@@ -422,8 +437,14 @@
crypt
end
-end
+ # :stopdoc:
+ def check(dict=nil)
+ # Load the crack module (which injects a check method into this class,
+ # overriding this one) and try again.
+ self.send("check") if require 'crack'
+ end
+end
# Display a phonemic password, if run directly.
#
|