{"id":491,"date":"2016-09-29T13:27:03","date_gmt":"2016-09-29T13:27:03","guid":{"rendered":"http:\/\/blog.lizefield.mobi\/?p=491"},"modified":"2016-09-29T13:27:03","modified_gmt":"2016-09-29T13:27:03","slug":"devise%e3%81%aepassword%e6%9a%97%e5%8f%b7%e5%8c%96%e3%82%92%e7%84%a1%e5%8a%b9%e3%81%ab%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/2016\/09\/29\/devise%e3%81%aepassword%e6%9a%97%e5%8f%b7%e5%8c%96%e3%82%92%e7%84%a1%e5%8a%b9%e3%81%ab%e3%81%99%e3%82%8b\/","title":{"rendered":"devise\u306epassword\u6697\u53f7\u5316\u3092\u7121\u52b9\u306b\u3059\u308b"},"content":{"rendered":"<p>\u3042\u308a\u5f97\u306a\u3044\u5b9f\u88c5\u3060\u3051\u308c\u3069\u3082\u3001\u5fdc\u7528\u306e\u305f\u3081\u306e\u30e1\u30e2\u3002<a href=\"http:\/\/hir-aik.hatenablog.com\/entry\/2014\/10\/03\/181030\" target=\"_blank\" rel=\"nofollow\">\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u3044\u305f\u30b5\u30a4\u30c8<\/a><\/p>\n<p>rails:5.0.0<br \/>\nruby:2.2.4p230<\/p>\n<p><!--more--><\/p>\n<ol>\n<li><a href=\"#li1\"><b>devise-encryptable<\/b>\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<li><a href=\"#li2\"><b>User<\/b>\u30e2\u30c7\u30eb\u3078<b>encryptable<\/b>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u8ffd\u52a0<\/a><\/li>\n<li><a href=\"#li3\"><b>password_salt<\/b>\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<\/a><\/li>\n<li><a href=\"#li4\">\u6697\u53f7\u5316\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/a><\/li>\n<li><a href=\"#li5\"><b>seed<\/b>\u3067<b>User.create<\/b>\u6642\u306e\u6ce8\u610f<\/a><\/li>\n<\/ol>\n<hr \/>\n<h3 id=\"li1\">devise-encryptable\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>Gemfile\u3078\u4ee5\u4e0b\u3092\u8ffd\u8a18\u3057\u3001bundle install\u3092\u884c\u3046\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngem &quot;devise-encryptable&quot;\n<\/pre>\n<h3 id=\"li2\">User\u30e2\u30c7\u30eb\u3078encryptable\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u8ffd\u52a0<\/h3>\n<p>:encryptable\u3092\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass User &lt; ApplicationRecord\n  # Include default devise modules. Others available are:\n  # :confirmable, :lockable, :timeoutable and :omniauthable\n  devise :database_authenticatable, :registerable, :encryptable,\n         :recoverable, :rememberable, :trackable, :validatable\nend\n<\/pre>\n<h3 id=\"li3\">password_salt\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<\/h3>\n<p>devise-encryptable\u3092\u5229\u7528\u3059\u308b\u306b\u306fUsers\u30c6\u30fc\u30d6\u30eb\u306bpassword_salt\u306e\u30ab\u30e9\u30e0\u304c\u5fc5\u8981\u3068\u306a\u308b\u306e\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nrails g migration AddPasswordSaltToUsers password_salt:string\n<\/pre>\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3059\u308b\u3002\uff08\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\u5834\u6240\u3092:after\u3067\u6307\u5b9a\u3057\u305f\u3060\u3051\uff09<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass AddPasswordSaltToUsers &lt; ActiveRecord::Migration[5.0] def change add_column :users, :password_salt, :string, :after =&gt; :encrypted_password\n  end\nend\n<\/pre>\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nrails db:migrate\n<\/pre>\n<h3 id=\"li4\">\u6697\u53f7\u5316\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/h3>\n<p>config\/initializers\/devise_encryptor.rb\u3092\u4f5c\u6210\u3059\u308b\u3002\u6697\u53f7\u5316\u3057\u306a\u3044\u306e\u3067digest\u3068compare\u3092password\u305d\u306e\u307e\u307e\u4f7f\u3046\u3088\u3046\u306b\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/plataformatec\/devise-encryptable\" target=\"_blank\" rel=\"nofollow\">devise-encriptable<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule Devise\n  module Encryptable\n    module Encryptors\n      class PasswordAuthentification &lt; Base\n        def self.digest(password, stretches, salt, pepper)\n          password\n        end\n\n        def self.salt(stretches)\n        end\n\n        def self.compare(encrypted_password, password, stretches, salt, pepper)\n          encrypted_password == password\n        end\n      end\n    end\n  end\nend\n<\/pre>\n<p>config\/initializers\/devise.rb\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n  # config.encryptor = :sha512\n  config.encryptor = :password_authentification\n<\/pre>\n<h3 id=\"li5\">seed\u3067User.create\u6642\u306e\u6ce8\u610f<\/h3>\n<p>\u521d\u671f\u30c7\u30fc\u30bf\u4f5c\u6210\u306e\u305f\u3081\u306bseed\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u3044\u305f\u5834\u5408\u3001<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nUser.create!(password: 'pass', password_confirmation: 'pass', uid: 'test', name: 'testuser')\n<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u305f\u3089\u767b\u9332\u51fa\u6765\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nUser.create!(password: 'pass', encrypted_password: 'pass', uid: 'test', name: 'testuser')\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3042\u308a\u5f97\u306a\u3044\u5b9f\u88c5\u3060\u3051\u308c\u3069\u3082\u3001\u5fdc\u7528\u306e\u305f\u3081\u306e\u30e1\u30e2\u3002\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u3044\u305f\u30b5\u30a4\u30c8 rails:5.0.0 ruby:2.2.4p230<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[32,37,57,62],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/491"}],"collection":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":0,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"wp:attachment":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}