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

Class Method Details

.base64(pass, layers: 1) ⇒ String

Encodes password in Base64.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:

  • (String)

    Returns the Base64-encoded version of the password



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.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:

  • (String)

    The 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.

Parameters:

  • options (Array)

    Options for the password given in strings. Available strings ‘number` `upletter` `downletter` `symbol`

  • length (Integer)

    How long the password will be

Returns:

  • (String)

    Returns the Base64-encoded version of the password.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/passlock.rb', line 22

def self.cpass(options, length)
  options = options != Array || options.empty? ? options : %w(number upletter downletter symbol)
  length = length.is_a?(Integer) && length > 0 ? length : 10
  chars = []
  result = ''
  options.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.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:



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.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:

  • (String)

    The 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.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:

  • (String)

    The 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.

Parameters:

  • pass (String)

    The password to be encoded

  • layers (Fixnum) (defaults to: 1)

    The amount of layering

Returns:

  • (String)

    The 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

.uuidString

Creates a UUID.

Returns:



38
39
40
# File 'lib/passlock.rb', line 38

def self.uuid
  SecureRandom.uuid
end