/plugin.rb Secret
Last active
August 29, 2015 14:05
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
# name: altpwd | |
# about: enable alternative password hash algorithms | |
# version: 0.1 | |
# authors: Jens Maier | |
require 'digest' | |
after_initialize do | |
module ::AlternativePassword | |
def confirm_password?(password) | |
return true if super | |
return false unless self.custom_fields.has_key?('import_pass') | |
salt, password_hash = self.custom_fields['import_pass'].split(':') | |
if password_hash == AlternativePassword::hash_password(password, salt) | |
self.password = password | |
self.custom_fields.delete('import_pass') | |
return save | |
end | |
false | |
end | |
def self.hash_password(password, salt) | |
Digest::SHA1.hexdigest(salt + password) | |
end | |
end | |
class ::User | |
prepend AlternativePassword | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment