lib/blogaze/models/user.rb in blogaze-0.0.2 vs lib/blogaze/models/user.rb in blogaze-0.0.3
- old
+ new
@@ -12,10 +12,18 @@
plugin :validation_helpers
one_to_many :post
many_to_one :group
+ ##
+ # Check if the users password matches
+ # the supplied password.
+ #
+ def check_password(password)
+ BCrypt::Password.new(self.password) == password
+ end
+
def validate
super
# Username
validates_unique :username
@@ -30,10 +38,10 @@
validates_unique :email
validates_format /(.*)@(.*)\.(.*)/, :email, :message => 'is not a valid email'
end
def before_create
- self.password = Digest::SHA1.hexdigest(self.password)
+ self.password = BCrypt::Password.create(self.password)
self.group_id = 3
end
def before_save
end