Skip to content

Instantly share code, notes, and snippets.

@Elberet
Last active August 29, 2015 14:05
# 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