diy一下devise的验证
生活随笔
收集整理的這篇文章主要介紹了
diy一下devise的验证
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
devise-encryptable地址
https://github.com/plataformatec/devise-encryptable.git
1.在 Gemfile 中加入devise-encryptable
gem "devise-encryptable"
在devise的user/member model里加入 :encryptable:
class User < ActiveRecord::Base?devise :database_authenticatable, :encryptableend
然后用migration添加一個password_salt:
class DeviseCreateUsers < ActiveRecord::Migration?def change
? ?add_column :users, :password_salt, :string
?end
end
2.添加自己的驗證方式
在 /config/initializers/下創建md5.rb:
require 'digest/md5'module Devise?module Encryptable
? ?module Encryptors
? ? ?class Md5 < Base
? ? ? ?def self.digest(password, stretches, salt, pepper)
? ? ? ? ?password = Digest::MD5.hexdigest password ? ? ? ? ?Digest::MD5.hexdigest(password + salt) ? ? ? ?end
? ? ? ?def self.salt(stretches)
? ? ? ? ?(Digest::MD5.hexdigest (0...50).map { ('a'..'z').to_a[rand(26)] }.join)[0,32] ? ? ? ?end
? ? ?end
? ?end
?endend
然后在相同目錄下打開 devise.rb
加入:
rails s使用devise注冊登陸 就是你的驗證方式了
轉載于:https://my.oschina.net/imot/blog/414811
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的diy一下devise的验证的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS3 box flex 布局
- 下一篇: tinyhttpd源码详解