lockr 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lockr.rb CHANGED
@@ -43,12 +43,12 @@ class Lockr
43
43
 
44
44
  options[:keyfile] = nil
45
45
  opts.on( '-k', '--keyfile FILE', 'the FILE to use as key for the password encryption') do |file|
46
- options[:keyfile] = file
46
+ options[:keyfile] = File.expand_path(file)
47
47
  end
48
48
 
49
49
  options[:vault] = 'vault.yaml'
50
50
  opts.on( '-v', '--vault FILE', 'FILE is the name of the vault to store the password sets') do |file|
51
- options[:vault] = file
51
+ options[:vault] = File.expand_path(file)
52
52
  end
53
53
 
54
54
  options[:generatepwd] = nil
@@ -63,7 +63,7 @@ class Lockr
63
63
  exit
64
64
  end
65
65
 
66
- opts.on('-v', '--version', 'Show version') do
66
+ opts.on('--version', 'Show version') do
67
67
  puts "Lockr #{LockrVer::VERSION} (#{LockrVer::DATE})"
68
68
  exit
69
69
  end
@@ -15,13 +15,17 @@ class ShowAction < AesAction
15
15
  pwd_directory_id = YAML::load(decrypt( pwd_directory[id][:enc], keyfilehash, pwd_directory[id][:salt]))
16
16
 
17
17
  if username.nil?
18
- unless pwd_directory_id.length == 1
19
- puts "More than one username for id '#{id}'. Please provide a username!"
20
- exit 13
18
+ if pwd_directory_id.length == 1
19
+ key = pwd_directory_id.keys[0]
20
+ store = pwd_directory_id[key]
21
+ else
22
+ puts "More than one username for id '#{id}'."
23
+ while username.nil?
24
+ username = ask("Username? ") { |q| }
25
+ username = nil if username.strip == ''
26
+ end
27
+ store = pwd_directory_id[username]
21
28
  end
22
-
23
- key = pwd_directory_id.keys[0]
24
- store = pwd_directory_id[key]
25
29
  else
26
30
  unless pwd_directory_id.has_key?(username)
27
31
  puts "Username '#{username}' not found for id '#{id}'"
data/lib/lockr/config.rb CHANGED
@@ -5,11 +5,17 @@ class Configuration
5
5
  def initialize()
6
6
  @config = nil
7
7
 
8
- filename = File.expand_path("~/#{CONFIG_FILE}")
9
- if File.exists?( filename)
10
- File.open( filename, 'r') do |f|
8
+ if File.exists?( CONFIG_FILE)
9
+ File.open( CONFIG_FILE, 'r') do |f|
11
10
  @config = YAML::load(f)
12
11
  end
12
+ else
13
+ filename = File.expand_path("~/#{CONFIG_FILE}")
14
+ if File.exists?( filename)
15
+ File.open( filename, 'r') do |f|
16
+ @config = YAML::load(f)
17
+ end
18
+ end
13
19
  end
14
20
  end
15
21
  end
data/lib/lockr/pwdgen.rb CHANGED
@@ -1,25 +1,44 @@
1
1
  require 'securerandom'
2
+ require 'highline/import'
2
3
 
3
4
  class PasswordGenerator
4
5
 
6
+ ALPHA = ('A'..'Z').to_a|('a'..'z').to_a
7
+ ALPHA_NUM = ('A'..'Z').to_a|('a'..'z').to_a|('0'..'9').to_a
8
+ ALPHA_NUM_SYM = (' '..'!').to_a|('#'..'[').to_a|(']'..'~').to_a
9
+
10
+ # generate a random password.
11
+ # format of parameter:
12
+ # rxx - r = type (a ... alpha, n ... alpha + num, s ... alpha + num + sym) and xx = password length
13
+ #
14
+ # example: n10 -> GcQfP4OBFh
15
+ # a12 -> DChpRnhpHiha
16
+ # s18 -> JHnXZ<hrcVKorO6mO:
5
17
  def generate( params)
6
18
  pwd = []
19
+ range = nil
7
20
 
8
- # create x random characters
9
- params.to_i.times do
10
- l = SecureRandom.random_number(26)
11
- pwd << l
21
+ case params[0]
22
+ when 's'
23
+ range = ALPHA_NUM_SYM
24
+ when 'n'
25
+ range = ALPHA_NUM
26
+ when 'a'
27
+ range = ALPHA
28
+ else
29
+ puts 'Invalid parameter: ' + params
30
+ exit 50
12
31
  end
13
32
 
14
- # up/downcase with 50% chance
15
- pwd.collect!{ |i| (i + 65).chr }.collect!{ |c|
16
- if ( SecureRandom.random_number(0) > 0.5)
17
- c.downcase
18
- else
19
- c
20
- end
21
- }
33
+ # create x random characters
34
+ params[1..params.length].to_i.times do
35
+ l = SecureRandom.random_number(range.length)
36
+ pwd << range[l]
37
+ end
22
38
 
23
- pwd.join
39
+ pwd = pwd.join
40
+ # print pwd with single quote escape
41
+ say( "<%= color( 'Generated password: #{pwd.gsub( "'", "\\\\'")}', :yellow) %>")
42
+ pwd
24
43
  end
25
44
  end
data/lib/lockr/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module LockrVer
2
- VERSION = "0.2.1"
3
- DATE = "2012-08-10"
2
+ VERSION = "0.3.0"
3
+ DATE = "2012-08-13"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &70152742830400 !ruby/object:Gem::Requirement
16
+ requirement: &70208522621980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70152742830400
24
+ version_requirements: *70208522621980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70152742829840 !ruby/object:Gem::Requirement
27
+ requirement: &70208522620300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70152742829840
35
+ version_requirements: *70208522620300
36
36
  description: Store your passwords AES encrypted in a simple yaml file
37
37
  email: info@byteblues.com
38
38
  executables: