dash 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dash.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'dash'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'dash'
8
+ end
9
+
10
+ Dash.hash(ARGV)
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dash/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dash"
7
+ s.version = Dash::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael McClenaghan"]
10
+ s.email = ["mike@shift81.com"]
11
+ s.homepage = "https://github.com/shift81/dash"
12
+ s.summary = %q{Strong password generator}
13
+ s.description = %q{Generates a strong password that is simple to recreate so there is no need to ever store your passwords.}
14
+
15
+ s.rubyforge_project = "dash"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('slop', '= 2.0.0')
23
+ end
@@ -0,0 +1,52 @@
1
+ require 'digest/sha2'
2
+ require 'slop'
3
+
4
+ module Dash
5
+ extend self
6
+ STRONG = 'ABCDEFGHJKLMNPQRSTUVWabcdefghijkmnopqrstuvw0123456789+/-_*()[]{}'
7
+ WEAK = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
8
+ LENGTH = 12
9
+
10
+ def hash(args)
11
+ return unless parse_args(args)
12
+
13
+ @key = encrypt @password
14
+ @hash = encrypt "#{@key}#{@domain}"
15
+
16
+ puts encode(@hash, @charset)[0,@length]
17
+ end
18
+
19
+ def parse_args(args)
20
+ opts = Slop.parse!(args) do
21
+ banner "Usage: dash <domain> [options]"
22
+ on :p, :password, 'Your master password', :argument => true
23
+ on :w, :weak, 'Generate weak password with alphanumeric character set'
24
+ on :l, :length, 'Length of generated password', :argument => true
25
+ end
26
+
27
+ @charset = opts.weak? ? WEAK : STRONG
28
+ @length = opts.length? ? opts[:length].to_i : LENGTH
29
+
30
+ unless password = opts[:password] || ENV['DASH_PASSWORD']
31
+ puts opts.help
32
+ return
33
+ end
34
+
35
+ unless domain = args.shift
36
+ puts opts.help
37
+ return
38
+ end
39
+
40
+ @password = password.strip
41
+ @domain = domain.strip
42
+ true
43
+ end
44
+
45
+ def encode(s,c)
46
+ (t=s.unpack('C*').inject([0,'',0]){|a,v|a[0]==0?[2,a[1]+c[v>>2,1],v*16&48]:a[0]==2?[4,a[1]+c[v>>4|a[2],1],v*4&60]:[0,a[1]+c[v>>6|a[2],1]+c[v&63,1],0]})[1]+(t[0]==0?'':t[0]==2?c[t[2],1]+'==':c[t[2],1]+'=')
47
+ end
48
+
49
+ def encrypt(key)
50
+ Digest::SHA2.hexdigest key
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Dash
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dash
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Michael McClenaghan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-11 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: slop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Generates a strong password that is simple to recreate so there is no need to ever store your passwords.
38
+ email:
39
+ - mike@shift81.com
40
+ executables:
41
+ - dash
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Rakefile
50
+ - bin/dash
51
+ - dash.gemspec
52
+ - lib/dash.rb
53
+ - lib/dash/version.rb
54
+ has_rdoc: true
55
+ homepage: https://github.com/shift81/dash
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: dash
84
+ rubygems_version: 1.4.2
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Strong password generator
88
+ test_files: []
89
+