Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < Sequel::Model
- plugin :validation_helpers
- attr_accessor :password
- attr_accessor :password_confirmation
- def validate
- validates_presence [:email, :username]
- validates_unique [:email, :username]
- end
- def after_create
- self.crypted_password = encrypt(password)
- self.created_at = Time.now
- @new = false
- save
- end
- def authenticated?(pass)
- crypted_password == encrypt(pass)
- end
- def self.authenticate(hash)
- mail, pass = hash['login'], hash['password']
- if user = User[:email => mail]
- return user unless pass
- user if user.authenticated?(pass)
- end
- end
- def encrypt(password)
- self.class.encrypt(password, salt)
- end
- def self.encrypt(password, salt)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
- end
Add Comment
Please, Sign In to add comment