EllisLab text mark
Advanced Search
1 of 2
1
   
CodeIgniter Community Voice - Mathew Davies
Posted: 30 June 2008 06:17 PM   [ Ignore ]
Avatar
Joined: 2006-03-23
3194 posts

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

 
Posted: 30 June 2008 09:42 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-05-21
340 posts

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 ]

 
Posted: 30 June 2008 09:49 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-11-08
237 posts

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.

 
Posted: 30 June 2008 11:17 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-07
2482 posts

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 
 
Posted: 01 July 2008 11:50 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2007-05-21
340 posts

Inparo thanks to you too wink

will need your community voice soon smile

 Signature 

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

 
Posted: 03 July 2008 12:01 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2006-09-07
3 posts

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….

 
Posted: 03 July 2008 12:03 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2007-11-08
237 posts

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

 Signature 

Redux Auth is no longer maintained.

 
Posted: 03 July 2008 03:11 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2006-09-07
3 posts

Aha! I see it now!

 
Posted: 03 July 2008 03:42 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-27
26 posts

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

 
Posted: 03 July 2008 03:51 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2007-11-08
237 posts

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.

 
Posted: 04 July 2008 02:22 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-13
378 posts

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

 
Posted: 04 July 2008 06:37 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-07
2482 posts

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 
 
Posted: 10 July 2008 02:07 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2008-01-04
4 posts

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)),0SALT_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_password0SALT_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

 
Posted: 14 October 2009 10:27 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2009-08-27
17 posts
Popcorn - 03 July 2008 07: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

 
Posted: 15 October 2009 11:52 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2007-11-08
237 posts

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.

 
Posted: 15 October 2009 12:03 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2009-08-27
17 posts

oo i see, thanks for the reply smile

 Signature 

keep calm and good for others

 
1 of 2
1