module PassLock

PassLock base module

Constants

VERSION

The version of the gem installed.

Public Class Methods

base64(pass, layers: 1) click to toggle source

Encodes password in Base64. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] Returns the Base64-encoded version of the password

# 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) click to toggle source

Encodes password in Base64 encoded hash. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] The Base64-encoded hash

# 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) click to toggle source

A randomly generated passord. @param options [Array] Options for the password given in strings. Available strings ‘number` `upletter` `downletter` `symbol` @param length [Integer] How long the password will be @return [String] Returns the Base64-encoded version of the password.

# 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) click to toggle source

Creats a SHA1 hash. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] The SHA1 hash

# 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) click to toggle source

Creats a SHA256 hash. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] The SHA256 hash

# 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) click to toggle source

Creats a SHA384 hash. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] The SHA384 hash

# 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) click to toggle source

Creats a SHA512 hash. @param pass [String] The password to be encoded @param layers [Fixnum] The amount of layering @return [String] The SHA512 hash

# 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() click to toggle source

Creates a UUID. @return [String] The UUID

# File lib/passlock.rb, line 38
def self.uuid
  SecureRandom.uuid
end