note 72476 added to function.crypt

From: Date: Sat, 20 Jan 2007 07:19:35 +0000
Subject: note 72476 added to function.crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-121948@lists.php.net to get a copy of this message
The following sentences can lead to misunderstandings: "If the salt argument is not provided, one will be randomly generated by PHP each time you call this function." Comment: false for DES, true for MD5 ... "If you are using the supplied salt, you should be aware that the salt is generated once. If you are calling this function repeatedly, this may impact both appearance and security." Comment: true for DES, false for MD5 Two sentences nearby, and they are telling incompatible stories. At least I was confused for quit a time. My analysis after some tests: If the parameter 'salt' is omitted, there are two possibilities: * if the default encryption is Standard DES, there is a static salt provided. If you call crypt() with the same password again, the salt and the hash is the same. Effectively, there is no salt functionality. (untested) * if the default encryption is crypt MD5, always random salt is added, and multiple calls of crypt with the same password provide different salt and hashes. I have tested this to be true. Experiment (PHP version: 4.4.0 SuSE 10 and PHP version: 5.1.2 SuSE 11): <?php echo 'result: ' . crypt('somepassword'); echo 'result: ' . crypt('somepassword'); echo 'result: ' . crypt('somepassword'); ?> result: $1$K2D8DGwq$b05uO37aMwO4rnDlB9Rsi1 result: $1$aPBvu2y.$213YVEs8/5m.jMCXSScly/ result: $1$dW3Xu2p6$nuCtJe2zzlgBMLxN2oZCx/ I hope, i can prevent some headache. ---- Server IP: 192.35.244.50 Probable Submitter: 213.47.75.177 ---- Manual Page -- http://www.php.net/manual/en/function.crypt.php Edit -- https://master.php.net/note/edit/72476 Del: integrated -- https://master.php.net/note/delete/72476/integrated Del: useless -- https://master.php.net/note/delete/72476/useless Del: bad code -- https://master.php.net/note/delete/72476/bad+code Del: spam -- https://master.php.net/note/delete/72476/spam Del: non-english -- https://master.php.net/note/delete/72476/non-english Del: in docs -- https://master.php.net/note/delete/72476/in+docs Del: other reasons-- https://master.php.net/note/delete/72476 Reject -- https://master.php.net/note/reject/72476 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121948) next »