easy-password 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f056e37ceea3e23a858c33e196db7bd9f3f3592f2cb3df383bd9fbcca3792d02
4
- data.tar.gz: c076c96b63ccd1a9051e60121affba167817cc3dfcd8c19900a8ac2f4d80d3f1
3
+ metadata.gz: 54a098d1ce47983b62a9974c8e0a58c16cd7c8e8615471ef87a71a212570c96d
4
+ data.tar.gz: 0a2160479a05388c034b4afa854647e8332515bf818231ee3de7148c378cdeb3
5
5
  SHA512:
6
- metadata.gz: 72a1ae8b671eb4a90630fe6937fcdb7b07db4dd9e75bf44bca3ef070117489be4f9cfda153871d4e2fa62cea9ac9a1638a40e421036610dc697381b6dcb6e3a6
7
- data.tar.gz: 8bbb27aef4d0f2fc2617914a27affa593e3e78f87a324a50810b3ac0f9536537412262b01bba76aaffbc0aa66673ae19375dc092d4376f6c5f014007687da646
6
+ metadata.gz: cd75d1a35f64b1fd1f66895fdb8013a4023619277a8942539c929253ff0447e5ee760b20826858d23c55cb1ef63bb9c865b5986614366174909cf099977cbf19
7
+ data.tar.gz: 460e9b33b168c2deb2e75d3fb8a07670e4330202370d2c3ed8752d436f0b0700edaba01456333a0203152423fba0c62368a1d6276b1b31900a9383a557c2e828
@@ -0,0 +1,65 @@
1
+ require 'stringio'
2
+
3
+ class EasyPassword
4
+
5
+ private
6
+
7
+ # Source: https://gist.github.com/frezbo/08eb7064a33ad3d8a853cc80b874201f
8
+ def self.digest_md4(string)
9
+ # functions
10
+ mask = (1 << 32) - 1
11
+ f = proc {|x, y, z| x & y | x.^(mask) & z}
12
+ g = proc {|x, y, z| x & y | x & z | y & z}
13
+ h = proc {|x, y, z| x ^ y ^ z}
14
+ r = proc {|v, s| (v << s).&(mask) | (v.&(mask) >> (32 - s))}
15
+
16
+ # initial hash
17
+ a, b, c, d = 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
18
+
19
+ bit_len = string.size << 3
20
+ string += "\x80"
21
+ while (string.size % 64) != 56
22
+ string += "\0"
23
+ end
24
+ string = string.force_encoding('ascii-8bit') +
25
+ [bit_len & mask, bit_len >> 32].pack("V2")
26
+
27
+ if string.size % 64 != 0
28
+ fail "failed to pad to correct length"
29
+ end
30
+
31
+ io = StringIO.new(string)
32
+ block = ""
33
+
34
+ while io.read(64, block)
35
+ x = block.unpack("V16")
36
+
37
+ # Process this block.
38
+ aa, bb, cc, dd = a, b, c, d
39
+ [0, 4, 8, 12].each {|i|
40
+ a = r[a + f[b, c, d] + x[i], 3]; i += 1
41
+ d = r[d + f[a, b, c] + x[i], 7]; i += 1
42
+ c = r[c + f[d, a, b] + x[i], 11]; i += 1
43
+ b = r[b + f[c, d, a] + x[i], 19]
44
+ }
45
+ [0, 1, 2, 3].each {|i|
46
+ a = r[a + g[b, c, d] + x[i] + 0x5a827999, 3]; i += 4
47
+ d = r[d + g[a, b, c] + x[i] + 0x5a827999, 5]; i += 4
48
+ c = r[c + g[d, a, b] + x[i] + 0x5a827999, 9]; i += 4
49
+ b = r[b + g[c, d, a] + x[i] + 0x5a827999, 13]
50
+ }
51
+ [0, 2, 1, 3].each {|i|
52
+ a = r[a + h[b, c, d] + x[i] + 0x6ed9eba1, 3]; i += 8
53
+ d = r[d + h[a, b, c] + x[i] + 0x6ed9eba1, 9]; i -= 4
54
+ c = r[c + h[d, a, b] + x[i] + 0x6ed9eba1, 11]; i += 8
55
+ b = r[b + h[c, d, a] + x[i] + 0x6ed9eba1, 15]
56
+ }
57
+ a = (a + aa) & mask
58
+ b = (b + bb) & mask
59
+ c = (c + cc) & mask
60
+ d = (d + dd) & mask
61
+ end
62
+
63
+ [a, b, c, d].pack("V4")
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
1
  class EasyPassword
2
2
  # Version
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
 
data/lib/easy-password.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'openssl'
2
+ require_relative 'easy-password/md4'
2
3
 
3
4
  #
4
5
  # Adding a simple password generator and using it by default:
@@ -206,7 +207,10 @@ class EasyPassword
206
207
  # @return [String] hashed password
207
208
  #
208
209
  def self.ntlm(password)
209
- Digest::MD4.hexdigest(password.encode("utf-16le"))
210
+ # New version of OpenSSL doesn't provide MD4 anymore
211
+ # Digest::MD4.hexdigest(password.encode("utf-16le"))
212
+ self.digest_md4(password.encode("utf-16le").force_encoding('BINARY'))
213
+ .unpack1('H*')
210
214
  end
211
215
 
212
216
 
@@ -236,6 +240,12 @@ class EasyPassword
236
240
  end
237
241
 
238
242
 
243
+ # Override equality
244
+ def ==(other)
245
+ !other.nil? && other.is_a?(EasyPassword) && self.raw == other.raw
246
+ end
247
+
248
+
239
249
  # Get the plain text password
240
250
  #
241
251
  # @return [String] plain text password
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-password
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stéphane D'Alu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - easy-password.gemspec
68
68
  - lib/easy-password.rb
69
+ - lib/easy-password/md4.rb
69
70
  - lib/easy-password/version.rb
70
71
  homepage: https://github.com/sdalu/easy-password
71
72
  licenses:
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
- rubygems_version: 3.0.8
90
+ rubygems_version: 3.5.14
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: Password generator, checker, hasher