class Oplop

Constants

DEFAULT_LENGTH
LEGACY_LENGTH
VERSION

Attributes

label[R]
length[R]
master[R]

Public Class Methods

new(args={}) click to toggle source
# File lib/oplop.rb, line 14
def initialize(args={})
  @master = args[:master]
  @label = args[:label]
  @length = args[:length] || DEFAULT_LENGTH

  if @label =~ /^([0-9]*)?\*/
    (@length, @label) = @label.split('*')
    @length = length.to_i
    @length = LEGACY_LENGTH if length <= 0
  end
end
password(args={}) click to toggle source
# File lib/oplop.rb, line 10
def self.password(args={})
  self.new(args).password
end

Public Instance Methods

master_label() click to toggle source
# File lib/oplop.rb, line 26
def master_label
  @master_label ||= '%s%s' % [ master, label ]
end
password() click to toggle source
# File lib/oplop.rb, line 30
def password
  password = Base64.urlsafe_encode64(Digest::MD5.digest(master_label))

  if password.respond_to?(:encode)
    password = password.encode('UTF-8')
  end

  if m = password.match(/\d+/)
    password = '%s%s' % [ m[0], password ] if (m.begin(0) >= length)
  else
    password = '1%s' % password
  end

  password[0,length]
end