pwned_passwords 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pwned_passwords.rb +21 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6c0bd9ec5d722fe50c3a6d57e5bec257c677d055ea955a46d340341863e93bb
4
- data.tar.gz: c98cbe9ff713a3e79def2a6d8e0206e64eecd918846bfb442161e765aaa2e0db
3
+ metadata.gz: '040899314b81011390472b0d6d17b12782f2709049fcf157d44b225fb0f4c1b4'
4
+ data.tar.gz: 4be81b1de548f6eb7da54cdc121c45491e6dcef9290fdae7809e976a81cda5b2
5
5
  SHA512:
6
- metadata.gz: 3c5dcbff242f824dbc53403503edf5613126aa7e2d141b1e3d0bc2fd3f217b278f4b61a1b79c26a2f0a98eed9a567902acd54b589c5a69b60d0a29a388861a49
7
- data.tar.gz: 2d97f98214d2542e1cc9a49f655698c014392bfa254dbd3de2d11ab024de113a165790fe4479c6cb2d9b6880ff7a7333a62634156c4142e539d9e04b1492a767
6
+ metadata.gz: a91cb033aa4ff81f04f5d2c78671cbe700b4c59d55741d6beade0233c4f8c7cfb21b54bb1e79769d7ce6dbec6047b40509b3e17324231dc071ea9275157da3a7
7
+ data.tar.gz: 972e799eba853006cf5abd190eec843756c8f8f36170645f0bb5700b15b391cadbb6ea1630920e57f3fe2607dacb3223f7f29dd65a4091fb8df2c82c2ea330fb
@@ -30,4 +30,25 @@ class PwnedPasswords
30
30
  puts "This password is okay"
31
31
  end
32
32
  end
33
+
34
+ def self.score_password(password)
35
+ password_score = 0
36
+ hashed_password = Digest::SHA1.hexdigest password
37
+ hashed_password.upcase!
38
+ # get the first five characters
39
+ hashed_password_prefix = hashed_password[0,5]
40
+ hashed_password_suffix = hashed_password[5..-1]
41
+ query_url = "#{PWNED_PASSWORD_API}#{hashed_password_prefix}"
42
+ api_response = Faraday.get query_url
43
+ if api_response.body.length > 0
44
+ suffixes = api_response.body.split("\r\n")
45
+ suffixes.each do |line|
46
+ suffix,count = line.split(":")
47
+ if suffix == hashed_password_suffix
48
+ password_score = count.to_i
49
+ end
50
+ end
51
+ end
52
+ password_score
53
+ end
33
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwned_passwords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Day
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-27 00:00:00.000000000 Z
11
+ date: 2019-09-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Checks against the Pwned Passwords API using the first five characters
14
14
  of the SHA1 hash of a password to determine if it exists in previously disclosed