password_characters 0.1.2 → 1.0.0
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.
- checksums.yaml +4 -4
- data/bin/password_characters +3 -27
- data/lib/password_characters.rb +79 -2
- data/lib/password_characters/cli.rb +19 -0
- data/lib/password_characters/version.rb +1 -1
- data/password_characters.gemspec +5 -4
- metadata +29 -16
- data/lib/ordinal_parser.rb +0 -29
- data/lib/password_and_ordinals.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed3c346e67225b17346a58797191032b239a205
|
4
|
+
data.tar.gz: 876e3acd646486aafcce6a0d44273ea5a4164668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c650a5a4f95870ab1b14a8dd8ec5adc1bef30c0eacc9aaa04f601fe41312b811f4feeb18286b47551d8745874ef614bd34f4a71e64063bd5bb1246ead46ef238
|
7
|
+
data.tar.gz: 5b1fd2b96dae733e55656300cab0a5b400bafa5c3292caa3b1910acb9d9eabdeb52e915c214127cdfbe1904ee55f6283510ff124e6580fc32eb9d6484ef99e8f
|
data/bin/password_characters
CHANGED
@@ -1,29 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'password_characters/cli'
|
3
|
+
require 'password_characters'
|
3
4
|
|
4
|
-
|
5
|
-
require 'active_support/core_ext/string'
|
6
|
-
|
7
|
-
password = if ARGV.any?
|
8
|
-
ARGV[0]
|
9
|
-
else
|
10
|
-
puts 'Enter password:'
|
11
|
-
gets
|
12
|
-
end
|
13
|
-
|
14
|
-
character_ordinals = if ARGV.any?
|
15
|
-
ARGV[1]
|
16
|
-
else
|
17
|
-
puts 'Enter indices:'
|
18
|
-
gets
|
19
|
-
end
|
20
|
-
|
21
|
-
def character_ordinals_to_integer_array(character_ordinals)
|
22
|
-
character_ordinals.split(',').map(&:to_i)
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
puts PasswordAndOrdinals.new(password.squish, character_ordinals_to_integer_array(character_ordinals.squish)).characters.join ' '
|
27
|
-
rescue Exception => e
|
28
|
-
abort e.message
|
29
|
-
end
|
5
|
+
PasswordCharacters::CLI.start
|
data/lib/password_characters.rb
CHANGED
@@ -1,6 +1,83 @@
|
|
1
1
|
require "password_characters/version"
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext/object'
|
7
|
+
|
3
8
|
module PasswordCharacters
|
4
|
-
|
5
|
-
|
9
|
+
class PasswordAndOrdinals
|
10
|
+
def initialize(password, ordinals)
|
11
|
+
raise(ArgumentError, "#{ordinals} does not ask for any characters") if ordinals.empty?
|
12
|
+
raise(ArgumentError, "#{ordinals} only asks for one character") if ordinals.one?
|
13
|
+
|
14
|
+
raise(ArgumentError, "#{ordinals} does not only ask for integers") unless ordinals.all? { |o| o.is_a? Fixnum }
|
15
|
+
|
16
|
+
raise(ArgumentError, "#{ordinals} is not in ascending order") unless sorted?(ordinals)
|
17
|
+
|
18
|
+
raise(ArgumentError, "#{ordinals.uniq.to_sentence} duplicated in #{ordinals}") unless uniq?(ordinals)
|
19
|
+
raise(ArgumentError, "#{ordinals} would reveal entire password") unless ordinals.size < password.size # needs to come after checking duplicates
|
20
|
+
|
21
|
+
raise(ArgumentError, "#{ordinals_out_of_bounds(password, ordinals).to_sentence} out of bounds") unless ordinals.all? { |i| i.in? ordinal_range(password) }
|
22
|
+
|
23
|
+
@password_array = password.chars
|
24
|
+
@indices = indices ordinals
|
25
|
+
end
|
26
|
+
|
27
|
+
def characters
|
28
|
+
@indices.map { |i| @password_array.at i }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def sorted?(a)
|
34
|
+
a.sort == a
|
35
|
+
end
|
36
|
+
|
37
|
+
def uniq?(a)
|
38
|
+
a.uniq == a
|
39
|
+
end
|
40
|
+
|
41
|
+
def ordinals_out_of_bounds(password, ordinals)
|
42
|
+
ordinals.reject { |i| i.in? ordinal_range(password) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def ordinal_range(password)
|
46
|
+
1..password.length
|
47
|
+
end
|
48
|
+
|
49
|
+
def indices(ordinals)
|
50
|
+
ordinals.map { |n| n - 1 }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class OrdinalParser
|
55
|
+
def initialize(string, password=nil)
|
56
|
+
@input = string
|
57
|
+
@password = password
|
58
|
+
end
|
59
|
+
|
60
|
+
def ordinal
|
61
|
+
case @input
|
62
|
+
when /the last/
|
63
|
+
@password.length
|
64
|
+
when /second (from|to) last/
|
65
|
+
@password.length - 1
|
66
|
+
when /third from last/
|
67
|
+
@password.length - 2
|
68
|
+
when /fourth from last/
|
69
|
+
@password.length - 3
|
70
|
+
when /first/
|
71
|
+
1
|
72
|
+
when /second/
|
73
|
+
2
|
74
|
+
when /third/
|
75
|
+
3
|
76
|
+
when /fourth/
|
77
|
+
4
|
78
|
+
else
|
79
|
+
@input[/\d+/].to_i
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
6
83
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
|
5
|
+
module PasswordCharacters
|
6
|
+
class CLI < Thor
|
7
|
+
desc 'inline', 'allows input of the password and indices during invocation'
|
8
|
+
options password: :required, indices: :required
|
9
|
+
def inline
|
10
|
+
puts PasswordCharacters::PasswordAndOrdinals.new(options[:password], character_ordinals_to_integer_array(options[:indices])).characters.join ' '
|
11
|
+
end
|
12
|
+
|
13
|
+
no_commands do
|
14
|
+
def character_ordinals_to_integer_array(character_ordinals)
|
15
|
+
character_ordinals.split(',').map(&:to_i)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/password_characters.gemspec
CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
-
spec.add_development_dependency "rake", "~>
|
24
|
-
spec.add_development_dependency 'aruba', '0.14.1'
|
25
|
-
spec.add_development_dependency 'rspec', '3.
|
26
|
-
spec.add_runtime_dependency 'activesupport', '
|
23
|
+
spec.add_development_dependency "rake", "~> 11.2.2"
|
24
|
+
spec.add_development_dependency 'aruba', '~> 0.14.1'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
26
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.0.0.1'
|
27
|
+
spec.add_dependency 'thor'
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: password_characters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Lowry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,56 +30,70 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 11.2.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 11.2.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.14.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.14.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.5.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.5.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.0.0.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.0.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '0'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: '0'
|
83
97
|
description: Can be used to log in to Web sites which ask for specific characters
|
84
98
|
from your password
|
85
99
|
email:
|
@@ -101,9 +115,8 @@ files:
|
|
101
115
|
- bin/console
|
102
116
|
- bin/password_characters
|
103
117
|
- bin/setup
|
104
|
-
- lib/ordinal_parser.rb
|
105
|
-
- lib/password_and_ordinals.rb
|
106
118
|
- lib/password_characters.rb
|
119
|
+
- lib/password_characters/cli.rb
|
107
120
|
- lib/password_characters/version.rb
|
108
121
|
- password_characters.gemspec
|
109
122
|
homepage: https://github.com/nigel-lowry/password_characters
|
data/lib/ordinal_parser.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
class OrdinalParser
|
2
|
-
def initialize(string, password=nil)
|
3
|
-
@input = string
|
4
|
-
@password = password
|
5
|
-
end
|
6
|
-
|
7
|
-
def ordinal
|
8
|
-
case @input
|
9
|
-
when /the last/
|
10
|
-
@password.length
|
11
|
-
when /second (from|to) last/
|
12
|
-
@password.length - 1
|
13
|
-
when /third from last/
|
14
|
-
@password.length - 2
|
15
|
-
when /fourth from last/
|
16
|
-
@password.length - 3
|
17
|
-
when /first/
|
18
|
-
1
|
19
|
-
when /second/
|
20
|
-
2
|
21
|
-
when /third/
|
22
|
-
3
|
23
|
-
when /fourth/
|
24
|
-
4
|
25
|
-
else
|
26
|
-
@input[/\d+/].to_i
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_support/core_ext/object'
|
5
|
-
|
6
|
-
class PasswordAndOrdinals
|
7
|
-
def initialize(password, ordinals)
|
8
|
-
raise(ArgumentError, "#{ordinals} does not ask for any characters") if ordinals.empty?
|
9
|
-
raise(ArgumentError, "#{ordinals} only asks for one character") if ordinals.one?
|
10
|
-
|
11
|
-
raise(ArgumentError, "#{ordinals} is not in ascending order") unless sorted?(ordinals)
|
12
|
-
|
13
|
-
raise(ArgumentError, "#{ordinals.uniq.to_sentence} duplicated in #{ordinals}") unless uniq?(ordinals)
|
14
|
-
raise(ArgumentError, "#{ordinals} would reveal entire password") unless ordinals.size < password.size # needs to come after checking duplicates
|
15
|
-
|
16
|
-
raise(ArgumentError, "#{ordinals_out_of_bounds(password, ordinals).to_sentence} out of bounds") unless ordinals.all? { |i| i.in? ordinal_range(password) }
|
17
|
-
|
18
|
-
@password_array = password.chars
|
19
|
-
@indices = indices ordinals
|
20
|
-
end
|
21
|
-
|
22
|
-
def characters
|
23
|
-
@indices.map { |i| @password_array.at i }
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def sorted?(a)
|
29
|
-
a.sort == a
|
30
|
-
end
|
31
|
-
|
32
|
-
def uniq?(a)
|
33
|
-
a.uniq == a
|
34
|
-
end
|
35
|
-
|
36
|
-
def ordinals_out_of_bounds(password, ordinals)
|
37
|
-
ordinals.reject { |i| i.in? ordinal_range(password) }
|
38
|
-
end
|
39
|
-
|
40
|
-
def ordinal_range(password)
|
41
|
-
1..password.length
|
42
|
-
end
|
43
|
-
|
44
|
-
def indices(ordinals)
|
45
|
-
ordinals.map { |n| n - 1 }
|
46
|
-
end
|
47
|
-
end
|