From 1677ac79b73f125a1665d7346ad49404ef8ca4ae Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Wed, 31 Jul 2024 14:46:02 +0200 Subject: [PATCH] Add password_hash as an alias for encrypted_password --- lib/devise/models/database_authenticatable.rb | 2 ++ test/models/database_authenticatable_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/devise/models/database_authenticatable.rb b/lib/devise/models/database_authenticatable.rb index e16b7d8453..d7df5e49e4 100644 --- a/lib/devise/models/database_authenticatable.rb +++ b/lib/devise/models/database_authenticatable.rb @@ -37,6 +37,8 @@ module DatabaseAuthenticatable attr_reader :password, :current_password attr_accessor :password_confirmation + + alias_attribute :password_hash, :encrypted_password end def initialize(*args, &block) diff --git a/test/models/database_authenticatable_test.rb b/test/models/database_authenticatable_test.rb index 909e010458..16c2119df8 100644 --- a/test/models/database_authenticatable_test.rb +++ b/test/models/database_authenticatable_test.rb @@ -106,6 +106,12 @@ def setup assert_present user.encrypted_password end + + test 'should have a password_hash as an alias to encrypted_password' do + user = new_user + assert_equal user.encrypted_password, user.password_hash + end + test 'should support custom hashing methods' do user = UserWithCustomHashing.new(password: '654321') assert_equal '123456', user.encrypted_password