Part of the EllisLab Network
   
 
CodeIgniter Community Voice - Mathew Davies
Posted: 30 June 2008 04:17 PM   [ Ignore ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6566
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:  411
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:  195
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 Authentication is a great CodeIgniter Authentication library. It’s light, easy to use and has great features. It’s a great choice for your new or existing project due to the power it gives you.
LevelDesign - Teaching You Something Worthwhile / Mathew Davies - Web Designer / Developer

Profile
 
 
Posted: 30 June 2008 09:17 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1223
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 

Blog | Twitter | Coffee

Profile
 
 
Posted: 01 July 2008 09:50 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  411
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:  4
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:  195
Joined  11-08-2007

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

 Signature 

Redux Authentication is a great CodeIgniter Authentication library. It’s light, easy to use and has great features. It’s a great choice for your new or existing project due to the power it gives you.
LevelDesign - Teaching You Something Worthwhile / Mathew Davies - Web Designer / Developer

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

Aha! I see it now!

Profile
 
 
Posted: 03 July 2008 01:42 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  13
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:  195
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 Authentication is a great CodeIgniter Authentication library. It’s light, easy to use and has great features. It’s a great choice for your new or existing project due to the power it gives you.
LevelDesign - Teaching You Something Worthwhile / Mathew Davies - Web Designer / Developer

Profile
 
 
Posted: 04 July 2008 12:22 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  442
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 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1223
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 

Blog | Twitter | Coffee

Profile
 
 
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
 
 
   
 
 
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 719, on June 06, 2008 10:16 AM
Total Registered Members: 62402 Total Logged-in Users: 32
Total Topics: 76626 Total Anonymous Users: 1
Total Replies: 413857 Total Guests: 447
Total Posts: 490483    
Members ( View Memberlist )