From d03928ef4cc8e4e8c9628e2699877f9cb743add3 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 10 Oct 2011 22:31:51 +0200 Subject: [PATCH] making cryptography stuff in user public --- app/models/user.rb | 4 ++-- features/step_definitions/user_steps.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6b7d97eb..26ebe9c7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -225,8 +225,6 @@ class User < ActiveRecord::Base end end -protected - def salted(s) "#{Tracks::Config.salt}--#{s}--" end @@ -239,6 +237,8 @@ protected BCrypt::Password.create s end +protected + def crypt_password return if password.blank? write_attribute("crypted_password", hash(password)) if password == password_confirmation diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 4af46a87..dd1ef9b9 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -22,10 +22,10 @@ Given /^the following user records with hash algorithm$/ do |table| BCrypt::Password.new(user.crypted_password).should == password when 'sha1' user.password = user.password_confirmation = nil - user.write_attribute :crypted_password, Digest::SHA1.hexdigest("#{Tracks::Config.salt}--#{password}--") + user.write_attribute :crypted_password, user.sha1(password) user.save user.reload - user.crypted_password.should == Digest::SHA1.hexdigest("#{Tracks::Config.salt}--#{password}--") + user.crypted_password.should == user.sha1(password) else raise "Unknown hashing algorithm: #{algorithm}" end