Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'dm-core'
- require 'dm-types'
- require 'dm-validations'
- require 'dm-serializer'
- require 'dm-migrations'
- class User
- include DataMapper::Resource
- attr_accessor :password
- attr_accessor :password_confirmation
- def after_create
- self.crypted_password = encrypt(password)
- @new = false
- save
- end
- def authenticated?(password)
- crypted_password == encrypt(password)
- end
- def encrypt(password)
- self.class.encrypt(password, salt)
- end
- def self.encrypt(password, salt)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
- def self.authenticate(hash)
- mail, pass = hash['mail'], hash['password']
- if user = Player.first(:mail => mail)
- user if pass && user.authenticated?(pass)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement