Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCrypt Support #1727

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "rdoc"
group :test do
gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1"
gem "scrypt", "~> 1.0.3"
gem "webrat", "0.7.2", :require => false
gem "mocha", :require => false

Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
devise (2.0.4)
devise (2.1.0.rc)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
railties (~> 3.1)
Expand Down Expand Up @@ -124,6 +124,7 @@ GEM
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-openid (2.1.8)
scrypt (1.0.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
Expand Down Expand Up @@ -163,5 +164,6 @@ DEPENDENCIES
rails (~> 3.2.0)
rdoc
ruby-debug (>= 0.10.3)
scrypt (~> 1.0.3)
sqlite3-ruby
webrat (= 0.7.2)
1 change: 1 addition & 0 deletions lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Encryptors
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
autoload :BCrypt, 'devise/encryptors/bcrypt'
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
autoload :SCrypt, 'devise/encryptors/scrypt'
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
autoload :Sha512, 'devise/encryptors/sha512'
autoload :Sha1, 'devise/encryptors/sha1'
Expand Down
21 changes: 21 additions & 0 deletions lib/devise/encryptors/scrypt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
begin
require "scrypt"
rescue LoadError
$stderr.puts "You must install the scrypt gem in order to use SCrypt encryption."
exit(1)
end

module Devise
module Encryptors
class SCrypt < Base
def self.digest(password, stretches, salt, pepper)
::SCrypt::Engine.hash_secret("#{password}#{pepper}", salt)
end

def self.compare(encrypted_password, password, stretches, salt, pepper)
salt = ::SCrypt::Password.new(encrypted_password).salt
Devise.secure_compare(encrypted_password, digest(password, stretches, salt, pepper))
end
end
end
end
7 changes: 7 additions & 0 deletions test/encryptors_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require 'test_helper'

class Encryptors < ActiveSupport::TestCase
test 'should match a password created by scrypt' do
secret = '400$8$5$edf9769b2f75b26abfb539d649a5bbe2279b51da$1eb4af5f494573214e57f0521bf7c4d5c80fb793'
pepper = 'd90e854a76a208eeb7122c11b073d74597afdf78b0bf8eef2dce59652dcda61537963ec319bd1dcf30d6db3ac65c7efbbd4dd82d9b7a4cde2839ced708e03b37'
salt = '400$8$5$14a79bbc91b70a1fd5b5c02e75c14bd8e7f84d57'
encryptor = Devise::Encryptors::SCrypt.digest('123mudar', nil, salt, pepper)
end

test 'should match a password created by authlogic' do
authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
Expand Down