When life gives you Al2O3 (Corundum), make a ruby! When users give you passwords, make a secure hash algorithm. Well at least in this case we didn't have to make the algorithm. Instead all I have to do is use it.
Although I had the intention of posting this along with some additional material, I decided that this short post will stand on its own accord. And it should be considered important, especially since it has to do with data security.
So, I have my authentication / authorization system and now I need to make the data in my database a bit more secure (particularly the passwords for my users). So in one line I will be able to do that for my administrative portion.
Simply open up the Administrator model and add this line:
hashpasswd = Digest::SHA1.hexdigest(password)
That was simple! All I did was take the input (password) and pass it through the Secure Hash Algorithm1 to output a hash to my variable hashpasswd. Now just compare that with the password in the database (which also needs to be hashed!) and everything is good to go!
So how would I have done something similar in PHP? Well it actually takes less code in PHP to hash some input. Just provide the following line of code for PHP:
sha1($password)
It certainly saves a bit in typing, but no different in effectiveness.
Yes, this very well might be the shortest post I have made. But without a little motivation, you might not have any motivation at all. :-)
