-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "digest/sha1" | ||
|
||
module Devise | ||
module Encryptable | ||
module Encryptors | ||
# = Sha1 | ||
# Uses the Sha1 hash algorithm to encrypt passwords. | ||
class LdapSsha < Base | ||
# Generates a default password digest based on salt and the incoming password. | ||
def self.digest(password, stretches, salt, pepper) | ||
self.secure_digest(password, salt) | ||
end | ||
|
||
def self.salt(stretches) | ||
Devise.friendly_token[0,4] | ||
end | ||
|
||
private | ||
|
||
# Generate a SHA1 digest with salt | ||
def self.secure_digest(password, salt) | ||
raise "Invalid salt: #{salt}" if salt.size != 4 | ||
"{SSHA}" + Base64.encode64(Digest::SHA1.digest("#{password}#{salt}") + salt).strip | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters