diy一下devise的验证
生活随笔
收集整理的這篇文章主要介紹了
diy一下devise的验证
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
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添加一個(gè)password_salt:
class DeviseCreateUsers < ActiveRecord::Migration?def change
? ?add_column :users, :password_salt, :string
?end
end
2.添加自己的驗(yàn)證方式
在 /config/initializers/下創(chuàng)建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注冊(cè)登陸 就是你的驗(yàn)證方式了
轉(zhuǎn)載于:https://my.oschina.net/imot/blog/414811
超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的diy一下devise的验证的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS3 box flex 布局
- 下一篇: tinyhttpd源码详解