Module: Sinatra::Authentication::Cookies::Hashing

Extended by:
Hashing
Included in:
Hashing
Defined in:
lib/sinatra/authentication/cookies.rb

Instance Method Summary collapse

Instance Method Details

#check?(user_id, ip, key, crypted) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/sinatra/authentication/cookies.rb', line 18

def check?(user_id, ip, key, crypted)
    hash, salt = unserialize(crypted)
    self.hash(user_id, ip, key, salt) == hash
end

#decrypt(crypted, key) ⇒ Object



14
15
16
# File 'lib/sinatra/authentication/cookies.rb', line 14

def decrypt(crypted, key)
    Encryptor.decrypt(crypted, :key => key)
end

#encrypt(user_id, ip, key, salt = self.generate_salt) ⇒ Object



9
10
11
12
# File 'lib/sinatra/authentication/cookies.rb', line 9

def encrypt(user_id, ip, key, salt = self.generate_salt)
    hash = serialize(hash(user_id, ip, key, salt), salt)
    { :hash => hash, :salt => salt }
end