module Salty

Constants

ALPHA
SALT_LENGTH

Public Class Methods

check(unhashed,hashed) click to toggle source
# File lib/salty.rb, line 26
def Salty.check(unhashed,hashed)
  begin 
    n = unhashed.length
    salt = hashed[n,SALT_LENGTH]
    myhashed = hashed[0...n] + hashed[n+SALT_LENGTH..-1]

    return myhashed == salted_hash(unhashed,salt)
  rescue
    return false
  end
end
generate_salt() click to toggle source
# File lib/salty.rb, line 8
def Salty.generate_salt
  (1..SALT_LENGTH).map{ALPHA.sample}.join
end
hash(str) click to toggle source
# File lib/salty.rb, line 17
def Salty.hash(str)
  salt = generate_salt

  res = salted_hash(str,salt)

  n = str.length
  res[0...n] + salt + res[n..-1]
end
salted_hash(str,salt) click to toggle source
# File lib/salty.rb, line 12
def Salty.salted_hash(str,salt)
  pbkdf2 = PBKDF2.new(:password => str, :salt => salt, :iterations => 1000)
  pbkdf2.hex_string
end