LoginSignup
9
9

More than 5 years have passed since last update.

CakePHPで生成されたパスワードをRailsで認証する。

Last updated at Posted at 2014-07-04

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
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9