File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed
lib/authlogic/crypto_providers Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change 1
- begin
2
- require "bcrypt"
3
- rescue LoadError
4
- "sudo gem install bcrypt-ruby"
5
- end
1
+ require "bcrypt"
6
2
7
3
module Authlogic
8
4
module CryptoProviders
@@ -55,19 +51,19 @@ def cost
55
51
@cost ||= 10
56
52
end
57
53
attr_writer :cost
58
-
54
+
59
55
# Creates a BCrypt hash for the password passed.
60
56
def encrypt ( *tokens )
61
57
::BCrypt ::Password . create ( join_tokens ( tokens ) , :cost => cost )
62
58
end
63
-
59
+
64
60
# Does the hash match the tokens? Uses the same tokens that were used to encrypt.
65
61
def matches? ( hash , *tokens )
66
62
hash = new_from_hash ( hash )
67
63
return false if hash . blank?
68
64
hash == join_tokens ( tokens )
69
65
end
70
-
66
+
71
67
# This method is used as a flag to tell Authlogic to "resave" the password upon a successful login, using the new cost
72
68
def cost_matches? ( hash )
73
69
hash = new_from_hash ( hash )
@@ -77,12 +73,12 @@ def cost_matches?(hash)
77
73
hash . cost == cost
78
74
end
79
75
end
80
-
76
+
81
77
private
82
78
def join_tokens ( tokens )
83
79
tokens . flatten . join
84
80
end
85
-
81
+
86
82
def new_from_hash ( hash )
87
83
begin
88
84
::BCrypt ::Password . new ( hash )
Original file line number Diff line number Diff line change 1
- begin
2
- require "scrypt"
3
- rescue LoadError
4
- "sudo gem install scrypt"
5
- end
1
+ require "scrypt"
6
2
7
3
module Authlogic
8
4
module CryptoProviders
@@ -67,7 +63,7 @@ def matches?(hash, *tokens)
67
63
def join_tokens ( tokens )
68
64
tokens . flatten . join
69
65
end
70
-
66
+
71
67
def new_from_hash ( hash )
72
68
begin
73
69
::SCrypt ::Password . new ( hash )
You can’t perform that action at this time.
0 commit comments