Created
December 6, 2010 18:14
-
-
Save daniel-g/730671 to your computer and use it in GitHub Desktop.
Common tasks in my linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Common < Thor | |
desc "passgen [LENGTH]", "generates passwords with a given length (defaults to 8)" | |
method_options :numeric => :boolean, :downcase => :boolean, :upcase => :boolean, :alphanumeric => :boolean | |
def passgen(len = 8) | |
chars = [] | |
if (options.empty?) | |
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a | |
else | |
if options[:alphanumeric] | |
chars += ("a".."z").to_a + ("A".."Z").to_a | |
else | |
chars += ("a".."z").to_a if options[:downcase] | |
chars += ("A".."Z").to_a if options[:upcase] | |
end | |
chars += ("0".."9").to_a if options[:numeric] | |
end | |
newpass = "" | |
1.upto(len.to_i) { |i| newpass << chars[rand(chars.size-1)] } | |
puts newpass | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment