Part of the EllisLab Network
   
 
CodeIgniter Community Voice - Mathew Davies
Posted: 30 June 2008 04:17 PM   [ Ignore ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

EllisLab is blessed with two of the greatest communities that can be found anywhere on the internet in ExpressionEngine and more recently CodeIgniter.  Despite being a relative newcomer to the scene, the people attracted to CodeIgniter are among the smartest, most talented and down-to-earth developers around today.  From time to time we want to highlight some of these talented people, and we’ve asked them to lend their voice to ours.  Have your voice.  I hope you enjoy what they have to say as much as I did.

This week,  our Community Voice author is Mathew Davies (AKA Popcorn), author of the Redux Authentication library, a light, easy to use and fully featured auth engine. What follows is a brief discussion of some of the logic and security that went into the library, and considerations for your own programming.

Read the full article

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 30 June 2008 07:42 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  447
Joined  05-21-2007

Hey Mathew,

You just forgot to mention that CodeIgniter in fact uses a session encryption key, so the session cookie is more secure than he originally thought.

Not that is enough to make it rock solide, but still people will prolly love to hear that smile


Good job Mathew, glad to have you with us here.

 Signature 

-> None official irc channel [ irc.freenode.net #codeigniter ]

Profile
 
 
Posted: 30 June 2008 07:49 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  247
Joined  11-08-2007

Thanks for spotting that sikkle.

Ps : Everyone who replies to this thread also has to thank sikkle for being a great help to the community wink

Cheers.

 Signature 

Redux Auth is no longer maintained.

Profile
 
 
Posted: 30 June 2008 09:17 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Great read, and a really nice library as well.

Just to explain my quoted self real quick.  Double hashing, such as sha1(sha1($password)) or even more amusing sha1(md5($password)), is bad.  However, you may see people double hashing with an added salt.  That is known as key stretching and actually increases the strength of the hash.  In practice, you won’t do enough iterations to make a difference, so Mathew’s method is excellent (goes without saying).

On the cookie issue - decryption works against tampering, but theoretically you don’t need to decrypt the cookie to forge it.  You just have to present it to the site with the proper credentials and the server will decrypt it for you.  If you’re using CI sessions with the database that becomes very hard as you need to catch the user’s last request (along with his user agent and ip).  The database part is important though.

Chris Shiflett did an article a long time ago about Microsoft’s Passport system having a similar cookie vulnerability.  While outdated, it’s definitely worth a read.  It also shows that a clever person can turn a browser quirk into a security issue.  In fact, all of his articles are worth reading to get into the right mindset.

Keep up the great work.
And of course, thank you Sikkle smile .

 Signature 
Profile
MSG
 
 
Posted: 01 July 2008 09:50 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  447
Joined  05-21-2007

Inparo thanks to you too wink

will need your community voice soon smile

 Signature 

-> None official irc channel [ irc.freenode.net #codeigniter ]

Profile
 
 
Posted: 02 July 2008 10:01 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  5
Joined  09-06-2006

I’m confused about the microtime dynamic salt bit. How would i know the dynamic salt value when i need to compare the hashed value?

Or i’m missing something very obvious here….

Profile
 
 
Posted: 02 July 2008 10:03 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
RankRank
Total Posts:  247
Joined  11-08-2007

You store it on registration, then retreive it when you need to login.

 Signature 

Redux Auth is no longer maintained.

Profile
 
 
Posted: 03 July 2008 01:11 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  5
Joined  09-06-2006

Aha! I see it now!

Profile
 
 
Posted: 03 July 2008 01:42 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  24
Joined  03-27-2008

Excellent tips there Derek,

Is to seed your password the same as to salt? If they are different i think I can see how to salt may be more secure.

$seed = ‘6j3l23b35bdg’; //Some Random Generated numer
$password = ‘ilikecrownroyalinmycoffee’;
$secured_password = sha1($seed.$password);


Latavish

 Signature 

———————————
Programming Is an Art

Profile
 
 
Posted: 03 July 2008 01:51 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  247
Joined  11-08-2007

Humf, I wrote the article Latavish wink

What you have shown me is a dynamic salt value.

The best thing is to do something like this :

$dynamic_salt = ''; // Randomly generated salt value then store it in the users table.
$static_salt = ''; // Grab this salt value from a config file.

$password = 'password'; // Input password.

$secured_password = sha1($dynamic_salt.$static_salt.$password); // Secure
 Signature 

Redux Auth is no longer maintained.

Profile
 
 
Posted: 04 July 2008 12:22 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  443
Joined  12-13-2007

I am still failing to see how this is really anymore secure then using a static salt in the situation that your DB had been compromised (and brute forced with a rainbow hash) which Im led to believe is the main reason for using salt for passwords. The reason being that the dynamic salt can be actually seen in the table row that has been compromised and hence can be used as a part of the rainbow hash.

 Signature 

PX Webdesign | The Lab | Personal Blog

Profile
 
 
Posted: 04 July 2008 04:37 AM   [ Ignore ]   [ # 11 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Lone, rainbow tables don’t reverse the hash - they find a collision.

Hash functions aren’t perfect, they all have a size limit (160 bits in the case of sha1) so the birthday paradox applies to all of them.

If we have password x and assume that y = sha1(x), then we can find another password z where sha1(z) = y.  That works really well if they aren’t salted, because we now just punch z into the password field and the server authenticates us.  But with a salt the hash becomes different for the two.  So sha1(x) == sha1(z), but sha1(x+salt) != sha1(z+salt).

What the static salt does, is it stretches the key we hash so that the odds of finding that particular collision are lower.  Also if you have a very random password, and someone does manage to crack the hash, they won’t be able to tell where the salt ends and the password starts.

Something like this would have a similar effect, with a few more operations:

$salt = //something randomly generated and later inserted along with the password
$password = 'password';

$hashed = sha1($salt . sha1($salt . $password));

To truly reverse sha1, you would need to brute force it, which is not feasible (article explaining why).

 Signature 
Profile
MSG
 
 
Posted: 10 July 2008 12:07 PM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  5
Joined  01-04-2008

Hello Everybody,

There is an interesting article on phpsec.org about salted passwords. This is the philosophy :

define('SALT_LENGTH', 10) ;

//INSERT SALTED PASSWORD
$salt = substr(md5(uniqid(rand(), TRUE)),0, SALT_LENGTH) ; // $salt is randomly generated
$password = 'ilovesaltnpepa' ;

$salted_password = $salt . substr(sha1($salt . $password), 0, -SALT_LENGTH) ; // $salt is stored at the beginning of the password => sha1 has a length of 40 and the salt has a length of 10 : this explain -SALT_LENGTH...

// RETRIEVE SALT
$salt = substr($salted_password, 0, SALT_LENGTH); // $salt is retrieved from $salted_password

//You should know what to do next !

This way, the salt is not clearly stored in the database:  ;D

Profile
 
 
Posted: 14 October 2009 08:27 PM   [ Ignore ]   [ # 13 ]  
Summer Student
Avatar
Total Posts:  19
Joined  08-26-2009
Popcorn - 03 July 2008 01:51 PM

Humf, I wrote the article Latavish wink

What you have shown me is a dynamic salt value.

The best thing is to do something like this :

$dynamic_salt = ''; // Randomly generated salt value then store it in the users table.
$static_salt = ''; // Grab this salt value from a config file.

$password = 'password'; // Input password.

$secured_password = sha1($dynamic_salt.$static_salt.$password); // Secure

Hi Popcorn,
how to retrieve the password for ‘forgot password’? is it using reset password like wordpress?

 Signature 

keep calm and good for others

Profile
 
 
Posted: 15 October 2009 09:52 AM   [ Ignore ]   [ # 14 ]  
Lab Assistant
RankRank
Total Posts:  247
Joined  11-08-2007

Hi,

I found some mistakes in my article which make me look stupid, I was a less experienced developer back then.

dimazarno : You don’t, you setup a key system to verify their email address which will allow them to enter a new password through a form.

-Mathew

 Signature 

Redux Auth is no longer maintained.

Profile
 
 
Posted: 15 October 2009 10:03 AM   [ Ignore ]   [ # 15 ]  
Summer Student
Avatar
Total Posts:  19
Joined  08-26-2009

oo i see, thanks for the reply smile

 Signature 

keep calm and good for others

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120286 Total Logged-in Users: 48
Total Topics: 126407 Total Anonymous Users: 2
Total Replies: 664771 Total Guests: 386
Total Posts: 791178    
Members ( View Memberlist )