Salted hash login generator


#1

Hello all.

Has anyone managed to use SaltedHashLoginGenerator with Rails 2.2.2?

I’ve been following the simple steps on the README file.

When I run script/generate salted_login User Localization a
/config/environment/user_environment.rb file should be created, but
isn’t.

When I include the line: require ‘environments/user_environment’ in the
config/environment.rb file and start the server, it complains that the
user_environment.rb file is missing.

Does anyone know how to fix this?

I’m using Aptana IDE with RadRails.

Thanks.

Bruno


#2

Hi - if you can’t get this to work you could try building your own?

Class User

before_create :create_salt

def create_salt
unless self.salt
self.salt = random_salt
end
end

def random_salt
nums = (“0”…“9”).to_a
random = “”
1.upto(5) { |i| newrand << numbers[rand(numbers.size - 1)]}
return random
end

def hash_password
update_attribute :password, Digest::MD5.hexdigest("#{self.salt}#
{self.password.downcase}")
end

def password_matches? password_to_match
password == Digest::MD5.hexdigest("#{self.salt}#
{password_to_match.downcase}")
end
end

Just call hash_password after you save the user or update the password
and call password_matches? to check that the password provided is the
correct one.

Hope that helps?

On 17 Feb, 18:20, Bruno P. removed_email_address@domain.invalid