Module: Sinatra::SessionAuth::ModelHelpers::ClassMethods
- Defined in:
- lib/sinatra/session_auth.rb
Instance Method Summary collapse
Instance Method Details
#authenticate(args = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/sinatra/session_auth.rb', line 25 def authenticate(args={}) login, pass = args[:login], args[:password] u = self.first(:login => login) return nil if u.nil? return u if self.encrypt(pass, u.salt) == u.hashed_password nil end |
#encrypt(pass, salt) ⇒ Object
21 22 23 |
# File 'lib/sinatra/session_auth.rb', line 21 def encrypt(pass, salt) Digest::SHA1.hexdigest(pass + salt) end |
#random_string(len) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sinatra/session_auth.rb', line 33 def random_string(len) chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a str = "" 1.upto(len) { |i| str << chars[rand(chars.size-1)] } return str end |