The Rails Way: Users and Passwords
therailsway.com
therailsway.com
If you have someone with access to your server or source control go rogue, every password entered into the website should be presumed compromised.
(Why attack stuff from your database, necessitating a costly rainbow table, when you have write access to Ruby code? The most obvious solution to me is just turning off Rails' feature to strip passwords out of the log, but given that you can monkeypatch anything you darn well please from anywhere, you have literally unbounded access to the cleartext params[:password] to steal any time you darn well please.)
Salting doesn't make it impossible, it just takes longer time.
In practice, the constant factor can be very large, so this isn't a meaningless trick.
The whole point of doing it randomly is that even if somebody figures out the salt for one user, they would still need to figure it out individually for every other user too. Using a "system", like you're doing, significantly decreases the effort required to figure out the salt.
I think it was in WWII where the Americans would intercept the German broadcasts, which were encrypted by Enigma. But because the Germans routinely broadcast the same sorts of information in the same format every day - weather reports, for example, it gave the US a known set of data of limited scope which significantly improved their chances of breaking the codes. What you are doing, especially because you're broadcasting it on the internet, is essentially the same thing.
So from my un-trained-in-cryptography eyes, the username approach is solid.
Previously I've used a hash of site-wide random string - password - user specific random string. For my latest project I've moved to phpass which is an implementation of bcrypt. My understanding is that in terms of security:
bcrypt > stretched salted hash > hashed salted hash > salted hash > hash > plaintext
Has anyone ever actually bothered to try implementing something like this over SHA/MD5?
my $p = Authen::Passphrase::SaltedDigest->new(
algorithm => "SHA-1",
salt_random => 1,
passphrase => "passphrase",
);
$p->to_rfc2307;
Here's how I implement bcrypt: my $p = Authen::Passphrase::BlowfishCrypt->new(
cost => 8,
salt_random => 1,
passphrase => "passphrase",
);
$p->to_rfc2307;
I save that $p->to_rfc2307 string to the database. When I want to verify the password, I don't have to worry about the algorithm in use, I just say: my $p = Authen::Passphrase->from_rfc2307( <whatever> );
$p->check_passphrase("passphrase") # returns true or false
Polymorphism is a wonderful thing. If I started using a salted digest and later wanted to switch to bcrypt, I could easily do that. But of course, I always just start with bcrypt.(There is other nice stuff, like a passphrase that never returns true from check_passphrase, for disabling accounts; and a subclass that stores the password in cleartext, for debugging.)
I am really shocked that a web framework like Rails requires you to do the salting manually. I wonder how many people, like the Perlmonks folks, got it completely wrong.
You'd think a web framework would abstract this common task away.
If I wrote a blog entry about how to perform proper car maintenance to increase your gas mileage, I wouldn't put in a plug for selling your car and buying a motorcycle/bicycle.