Ruby/Password - password handling for Ruby
require 'password'
begin
password = Password.get("New password")
p = Password.new(password)
p.check
rescue Password::WeakPassword => reason
puts reason
retry
end
Ruby/Password is a collection of password handling routines for Ruby, including an interface to CrackLib for the purposes of testing password strength.
Password.new(password)Password.get(message = "Password")Password.getc(message = "Password", mask = '*')Password.echo(on = true, masked = false)Password.random(length = 8)Password#crypt(type = Password::DES, salt = '')Password#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, so if the dictionary is located at /usr/lib/cracklib_dict.pwd, you would pass a dict of /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::BadDictionary exception is raised.
On success, true is returned. On failure, a Password::WeakPassword exception is raised.
Written by Ian Macdonald <ian@caliban.org>
Copyright (C) 2002-2003 Ian Macdonald This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Send all bug reports, enhancement requests and patches to the author.
$Id: password.rb,v 1.13 2003/11/12 09:25:40 ianmacd Exp $