note 104529 added to function.sha1
| From: | grosbedoatgmaildotcom at osu1 dot php dot net | Date: | Tue, 21 Jun 2011 14:45:10 +0000 |
| Subject: | note 104529 added to function.sha1 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180806@lists.php.net to get a copy of this message | ||
I just stumbled on these old comments and I would like to add some notes about the specifications
and usage of obscure() function by mVamer and ranko84.
First, the obscure() function should take 3 parameters :
obscure($password, $salt = null, $algorythm = "sha1");
Secondly, to get a randomly salted hash for a password, just call :
obscure($password);
Thirdly, to verify a password (even one with a randomly generated password), you do NOT need to
store the salt, just call the obscure function like this :
obscure($password_to_check, $hash_of_the_good_password);
As you may have noticed, we give the good password hash as the value for $salt.
Indeed, the particularity of this function is that it will always generate different variations of
one same password if you DON'T give a salt, but if you give one, it will give you the same
salt, and it is here used to verify a password.
So, basically, to verify if the password is good, just do :
if (obscure($password_to_check, $good_hash) == $good_hash) {
// Authentication is OK
} else {
// Authentication is wrong
}
As you can see, we don't verify directly the hash of $password because obscure() can generate
several variations of a same password, but with $good_hash as the salt, it will either return the
same hash if it is the good one, either a new hash.
----
Having said that, the 2 primary benefits of this obscure() function are :
- The salt is never directly stored and is randomly generated at each call and for each password,
and it is NEVER retrieved,
- The length of the hash is always the same, and this can deceive a lot of attackers.
And the primary problems :
- Uses sha1 as default (which is no more considered to be secure), but you can easily change it to
some other crypto algorithm (whirlpool or sha512 advised).
- The snowball effect is very slow -> this means that when you change a character or add one to
the password, the hash will have some sequences of characters, and you need to change more
characters to get a really different hash.
- Bear in mind that this function is public (so if you use it as it is, attackers may freely analyze
the code and prepare their attacks).
- This function was not made nor verified by a cryptanalyst, and I'm not one neither.
A seemingly better alternative has since been proposed here by an Anonymous on 29-Oct-2009 with his
function __hash() which is very configurable with custom __scramble() and __harvest(). But if you
use it, be careful to use very good functions (not necessarily complex ones as he may have said),
but cryptographically strong, and it is not easy to know what is and what is not.
For such reasons, I personnally keep on using an alterated version of obscure(), but even as it is,
it seems to me to be quite a good algorithm (bear in mind that nothing is unbreakable, but it can be
challenging enough).
If a cryptanalyst come accross this page, it would be very interesting to have his opinion about it.
----
Server IP: 69.147.83.197
Probable Submitter: 89.83.73.89
----
Manual Page -- http://www.php.net/manual/en/function.sha1.php
Edit -- https://master.php.net/note/edit/104529
Del: integrated -- https://master.php.net/note/delete/104529/integrated
Del: useless -- https://master.php.net/note/delete/104529/useless
Del: bad code -- https://master.php.net/note/delete/104529/bad+code
Del: spam -- https://master.php.net/note/delete/104529/spam
Del: non-english -- https://master.php.net/note/delete/104529/non-english
Del: in docs -- https://master.php.net/note/delete/104529/in+docs
Del: other reasons-- https://master.php.net/note/delete/104529
Reject -- https://master.php.net/note/reject/104529
Search -- https://master.php.net/manage/user-notes.php