jameswilding-passgen 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ # Try for the gem version, fallback on the development version.
5
+ begin
6
+ require 'passgen'
7
+ rescue LoadError
8
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'passgen')
9
+ end
10
+
11
+ options = {}
12
+
13
+ # Command line switches
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: passgen [options]"
16
+
17
+ opts.on('-l', '--length n', Integer, 'Make a password of length n (default is 10)') do |n|
18
+ options[:length] = n
19
+ end
20
+
21
+ opts.on('-H', '--hex', 'Output both plain text and hexdigest-encrypted versions of the password') do |hex|
22
+ options[:hex] = hex
23
+ end
24
+
25
+ end.parse!
26
+
27
+ # New password according to options
28
+ password = PassGen::Password.new(options)
29
+
30
+ # Show hexed password if requested
31
+ if options[:hex]
32
+ puts "Plain: #{password}"
33
+ puts "Hexed: #{password.hexed}"
34
+ else
35
+ puts password
36
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), 'passgen', 'password')
2
+
3
+ module PassGen
4
+ VERSION = '1.3.0'
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'digest/sha1'
2
+
3
+ module PassGen
4
+ class Password < String
5
+
6
+ LETTERS = ('a'..'z').to_a
7
+ NUMBERS = ('0'..'9').to_a
8
+
9
+ def initialize(options={})
10
+ @count = options[:length] || 10
11
+ super(random_characters)
12
+ rescue SystemStackError => e
13
+ raise e, 'try specifying a shorter password length'
14
+ end
15
+
16
+ def hexed
17
+ Digest::SHA1.hexdigest(self)
18
+ end
19
+
20
+ private
21
+ def random_characters(result=[])
22
+ @count.times do
23
+ result << random_character
24
+ end
25
+ unique_characters_in(result) == @count ? result.join : random_characters
26
+ end
27
+
28
+ def random_character
29
+ c = characters[rand(characters.length)]
30
+ rand(2).eql?(1) ? c : c.upcase
31
+ end
32
+
33
+ def characters
34
+ LETTERS + NUMBERS
35
+ end
36
+
37
+ def unique_characters_in(array)
38
+ array.map { |x| x.downcase rescue x }.uniq.length
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jameswilding-passgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ platform: ruby
6
+ authors:
7
+ - James Wilding
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Passgen quickly generates random, alphanumeric passwords of up to twenty characters.
17
+ email:
18
+ executables:
19
+ - passgen
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/passgen
26
+ - lib/passgen.rb
27
+ - lib/passgen/password.rb
28
+ has_rdoc: false
29
+ homepage:
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.2.0
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: random password generator
54
+ test_files: []
55
+