easy_passwords 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -8,13 +8,15 @@ easy_passwords.rb is a Ruby implementation of passwdqc's easy_passwords, a rando
8
8
  gem install easy_passwords
9
9
  ```
10
10
 
11
- ```
12
- gem easy_passwords
11
+ ```ruby
12
+ #Gemfile
13
+ gem 'easy_passwords'
13
14
  ```
14
15
 
15
16
  ## Goals
16
17
  - Passwords are easily to read
17
18
  - You can setup max password length in characters(useful when sending password in sms message)
19
+ - You can define separators list
18
20
 
19
21
  ## Usage
20
22
 
@@ -27,12 +29,18 @@ require 'easy_passwords'
27
29
 
28
30
  p EasyPassword.generate # => "employ7Royal"
29
31
  p EasyPassword.generate 5 # => "Peach"
32
+ p EasyPassword.generate 7, '|' # => "cat|eat"
30
33
  p EasyPassword.generate 15 # => "soggy*Apart9Odd"
31
34
  p EasyPassword.generate 2 # => raise error, min length is 3
32
35
 
33
36
  gen = EasyPassword.new # => #<EasyPasswords::Generator:0x9f6ec40 ...>
34
- p gen.generate # => "employ7Royal"
35
- p gen.generate 15 # => "soggy*Apart9Odd"
37
+ p gen.generate # => "employ7Royal"
38
+ p gen.generate 15 # => "soggy*Apart9Odd"
39
+
40
+
41
+ my_gen = EasyPassword.new('|') # => #<EasyPasswords::Generator:0x9f6ec40 ...>
42
+ p my_gen.generate # => "employ|Royal"
43
+ p my_gen.generate 15 # => "soggy|Apart|Odd"
36
44
  ```
37
45
 
38
46
  ## Contributing
@@ -47,3 +55,6 @@ p gen.generate 15 # => "soggy*Apart9Odd"
47
55
  - Based on gem https://github.com/iphoting/pwqgen.rb
48
56
  - Original Design and C implementation from <http://www.openwall.com/passwdqc/> by Solar Designer.
49
57
 
58
+ ## Legal
59
+
60
+ [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = 'easy_passwords'
7
7
  s.version = EasyPasswords::VERSION
8
8
  s.summary = "Easy passwords generator in Ruby"
9
- s.description = "Easy password is a Ruby implementation of passwdqc's easy_passwords, a random pronouncable password generator. Don't use it for serious projects :)"
9
+ s.description = "Easy password is a Ruby implementation of passwdqc's easy_passwords, a random pronouncable password generator. Probably don't use it in banks."
10
10
  s.authors = ["Pete"]
11
11
  s.email = 'piotr.bliszczyk@gmail.com'
12
12
  s.homepage = 'https://github.com/piotrze/easy_passwords'
@@ -7,10 +7,10 @@ require 'securerandom'
7
7
  # Examples
8
8
  #
9
9
  # EasyPasswords.generate
10
- # # => "merger*Hick$"
10
+ # # => "merger4Hick_"
11
11
  #
12
12
  # EasyPasswords.new.generate
13
- # # => "employ7Royal"
13
+ # # => "employ-Royal"
14
14
  #
15
15
  # EasyPasswords::Generator.new.generate
16
16
  # # => "Beige7Jacob2"
@@ -23,22 +23,27 @@ module EasyPasswords
23
23
  DEFAULT_MAX_LENGTH = 12
24
24
  MIN_WORD_LENGTH = 3
25
25
  MAX_WORD_LENGTH = 6
26
+ SEPARATORS = "-_123456789"
26
27
 
27
28
  # Public: Returns a random generated password string.
28
29
  #
29
30
  # max_length - max number of characters used in password, it could generate password shorter by 3 characters.
31
+ # separators - list of separators as a String
30
32
  #
31
33
  # Example
32
34
  #
33
35
  # generate 8
34
- # # => "Fun=Crop"
36
+ # # => "Fun-Crop"
37
+ #
38
+ # generate 8, '01'
39
+ # # => "Fun0Crop"
35
40
  #
36
41
  # generate
37
42
  # # => "spate7Coup"
38
43
  #
39
44
  # Returns a password string.
40
- def self.generate(max_length = DEFAULT_MAX_LENGTH)
41
- self::Generator.new.generate max_length
45
+ def self.generate(max_length = DEFAULT_MAX_LENGTH, separators = SEPARATORS)
46
+ self::Generator.new(separators).generate max_length
42
47
  end
43
48
 
44
49
  def self.new
@@ -46,9 +51,9 @@ module EasyPasswords
46
51
  end
47
52
 
48
53
  class Generator
49
- def initialize
54
+ def initialize(separators = EasyPasswords::SEPARATORS)
50
55
  @@wordlist_size = @@wordlist.length
51
- @@separators = "-_!$&*+=23456789".split(//)
56
+ @@separators = separators
52
57
  @@separators_size = @@separators.length
53
58
  @rand = SecureRandom
54
59
  end
@@ -60,7 +65,7 @@ module EasyPasswords
60
65
  # Example
61
66
  #
62
67
  # generate 8
63
- # # => "Fun=Crop"
68
+ # # => "Fun_Crop"
64
69
  #
65
70
  # generate
66
71
  # # => "spate7Coup"
@@ -94,9 +99,9 @@ module EasyPasswords
94
99
  def random_word(maxsize = EasyPasswords::MAX_WORD_LENGTH)
95
100
  list = if maxsize < EasyPasswords::MAX_WORD_LENGTH
96
101
  @@wordlist.select{|w| w.size <= maxsize }
97
- else
102
+ else
98
103
  @@wordlist
99
- end
104
+ end
100
105
  word = list[@rand.random_number(list.size)]
101
106
  @rand.random_number(2) == 0 ? word.capitalize : word
102
107
  end
@@ -1,3 +1,3 @@
1
1
  module EasyPasswords
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -3,12 +3,22 @@ require 'spec_helper'
3
3
  describe EasyPasswords do
4
4
  it "should return a random password" do
5
5
  password = EasyPasswords.generate
6
- debugger
7
6
  password.should_not be_nil
8
7
  password.should_not be_empty
9
8
  password.should be_kind_of(String)
10
9
  password.length.should be_within(7).of(10)
11
- end
10
+ end
11
+
12
+ it "should return a random password with custom separator" do
13
+ separator = '|'
14
+ password = EasyPasswords.generate 7, separator
15
+ password.should_not be_nil
16
+ password.should_not be_empty
17
+ password.should be_kind_of(String)
18
+ password.length.should be_within(7).of(7)
19
+ password.include?(separator)
20
+ end
21
+
12
22
 
13
23
  it "should return a short random password when given a length of 5" do
14
24
  password = EasyPasswords.generate 5
@@ -40,7 +50,18 @@ describe EasyPasswords::Generator do
40
50
  password.should_not be_empty
41
51
  password.should be_kind_of(String)
42
52
  password.length.should be_within(5).of(15)
43
- end
53
+ end
54
+
55
+
56
+ it "should return a password with custom separator" do
57
+ separator = '|'
58
+ password = EasyPasswords::Generator.new(separator).generate 7
59
+ password.should_not be_nil
60
+ password.should_not be_empty
61
+ password.should be_kind_of(String)
62
+ password.length.should be_within(7).of(7)
63
+ password.include?(separator)
64
+ end
44
65
 
45
66
  it "should raise error when given a length of 1" do
46
67
  expect {EasyPasswords::Generator.new.generate 1}.to raise_error
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_passwords
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-15 00:00:00.000000000 Z
12
+ date: 2014-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  description: Easy password is a Ruby implementation of passwdqc's easy_passwords,
63
- a random pronouncable password generator. Don't use it for serious projects :)
63
+ a random pronouncable password generator. Probably don't use it in banks.
64
64
  email: piotr.bliszczyk@gmail.com
65
65
  executables: []
66
66
  extensions: []