From f8c24bf813deead94b3bac788def6db4d9d9a1ae Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 11 Dec 2014 16:02:57 -0300 Subject: [PATCH] Add support for salted_md5 passwords --- app/models/user.rb | 4 ++++ test/unit/user_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 4f58793..2e12c3a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -201,6 +201,10 @@ class User < ActiveRecord::Base Digest::MD5.hexdigest(password) end + add_encryption_method :salted_md5 do |password, salt| + Digest::MD5.hexdigest(password+salt) + end + add_encryption_method :clear do |password, salt| password end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index ca72ff0..220755a 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -190,6 +190,12 @@ class UserTest < ActiveSupport::TestCase assert_equal '098f6bcd4621d373cade4e832627b4f6', user.crypted_password end + + def test_should_support_salted_md5_passwords + user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_md5', :salt => 'test') + assert_equal '05a671c66aefea124cc08b76ea6d30bb', user.crypted_password + end + def test_should_support_crypt_passwords user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'crypt', :salt => 'test') assert_equal 'teH0wLIpW0gyQ', user.crypted_password -- libgit2 0.21.2