Created
March 17, 2010 22:19
-
-
Save phss/335800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "dm-core" | |
require "dm-validations" | |
require "dm-timestamps" | |
require "digest" | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :username, String, :required => true, :unique => true | |
property :email, String | |
property :encrypted_password, String | |
property :salt, String | |
attr_accessor :password, :password_confirmation | |
validates_present :password, :password_confirmation | |
validates_is_confirmed :password | |
before :save do | |
self.salt = self.object_id.to_s + rand.to_s | |
self.encrypted_password = encrypt(password) | |
end | |
def match_password?(password) | |
encrypted_password == encrypt(password) | |
end | |
private | |
def encrypt(string) | |
Digest::SHA1.hexdigest("#{string}-blah-#{salt}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment