CakePHPで生成された暗号化されたパスワードをRailsで認証する方法。
1: CakePHPのプロジェクトファイルのapp/config/core.phpからSecurity.saltの文字列をコピーする。
Configure::write('Security.salt', 'ここのランダム文字列');
2: Railsのモデルの例
class Customer < ActiveRecord::Base
# has_secure_password これは使わない。
def authenticate_php(plain_text)
# password_encryptedはCakePHPで暗号化されたパスワード
password_php(plain_text) == self.password_encrypted
end
def password_php(plain_text)
cake_salt="Security.saltのランダム文字列"
# SHA1の場合
Digest::SHA1.hexdigest("#{cake_salt}#{plain_text}")
#SHA256の場合
#Digest::SHA256.hexdigest("#{cake_salt}#{plain_text}")
#MD5の場合
#Digest::MD5.hexdigest("#{cake_salt}#{plain_text}")
end