Module: PassLock
- Defined in:
- lib/passlock.rb,
lib/passlock/version.rb
Overview
PassLock base module
Defined Under Namespace
Classes: Decode
Constant Summary collapse
- VERSION =
The version of the gem installed.
'0.0.8'.freeze
Class Method Summary collapse
-
.base64(pass, layers: 1) ⇒ String
Encodes password in Base64.
-
.base64hash(pass, layers: 1) ⇒ String
Encodes password in Base64 encoded hash.
-
.cpass(options, length) ⇒ String
A randomly generated passord.
-
.sha1(pass, layers: 1) ⇒ String
Creats a SHA1 hash.
-
.sha256(pass, layers: 1) ⇒ String
Creats a SHA256 hash.
-
.sha384(pass, layers: 1) ⇒ String
Creats a SHA384 hash.
-
.sha512(pass, layers: 1) ⇒ String
Creats a SHA512 hash.
-
.uuid ⇒ String
Creates a UUID.
Class Method Details
.base64(pass, layers: 1) ⇒ String
Encodes password in Base64.
46 47 48 49 50 51 |
# File 'lib/passlock.rb', line 46 def self.base64(pass, layers: 1) layers.times do pass = Base64.encode64 pass end pass end |
.base64hash(pass, layers: 1) ⇒ String
Encodes password in Base64 encoded hash.
101 102 103 104 105 106 |
# File 'lib/passlock.rb', line 101 def self.base64hash(pass, layers: 1) layers.times do pass = Base64.encode64((HMAC::SHA1.new(pass) << 'base').digest).strip end pass end |
.cpass(options, length) ⇒ String
A randomly generated passord.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/passlock.rb', line 22 def self.cpass(, length) = != Array || .empty? ? : %w(number upletter downletter symbol) length = length.is_a?(Integer) && length > 0 ? length : 10 chars = [] result = '' .each do |flag| chars.concat(@opts[flag].scan(/./)) unless @opts[flag].nil? end length.to_i.times do result += chars.sample end result end |
.sha1(pass, layers: 1) ⇒ String
Creats a SHA1 hash.
57 58 59 60 61 62 |
# File 'lib/passlock.rb', line 57 def self.sha1(pass, layers: 1) layers.times do pass = Digest::SHA1.hexdigest pass end pass end |
.sha256(pass, layers: 1) ⇒ String
Creats a SHA256 hash.
68 69 70 71 72 73 |
# File 'lib/passlock.rb', line 68 def self.sha256(pass, layers: 1) layers.times do pass = Digest::SHA256.new.update(pass).to_s end pass end |
.sha384(pass, layers: 1) ⇒ String
Creats a SHA384 hash.
79 80 81 82 83 84 |
# File 'lib/passlock.rb', line 79 def self.sha384(pass, layers: 1) layers.times do pass = Digest::SHA384.new.update(pass).to_s end pass end |
.sha512(pass, layers: 1) ⇒ String
Creats a SHA512 hash.
90 91 92 93 94 95 |
# File 'lib/passlock.rb', line 90 def self.sha512(pass, layers: 1) layers.times do pass = Digest::SHA512.new.update(pass).to_s end pass end |
.uuid ⇒ String
Creates a UUID.
38 39 40 |
# File 'lib/passlock.rb', line 38 def self.uuid SecureRandom.uuid end |