From: businessman332211 at hotmail dot com
Operating system: linux server
PHP version: 4.4.2
PHP Bug Type: *Encryption and hash functions
Bug description: major problem with crypt()
Description:
------------
I use crypt, I use the first 2 letters of the username and create a
encryption, like below under encryption then database $password into the
database
perfect.
Now I come to where I am testing to see if it matches someone goes to
login in, they enter username, and password, I take there username, user
it as salt to encrypt there password in the same way, I take there
username, and there password and run it against the db for a match, if it
matches it returns true and pulls the result.
If it doesn't it returns false
supposedly, if it's just 1 character off then it doesn't work.
I used 951103902 for instance
if I add an extra letter at the end, or change one before it, it still
returns true, I tried it with random words too, this isn't suppose to
happen.
Reproduce code:
---------------
//encrypt
$salt = substr($username, 0, 2);
$password = crypt($password, $salt);
//decrypt
$salt = substr($username, 0, 2);
$enteredpass = crypt($enteredpass, $salt);
if ($enteredpass === $password){
echo "The passwords match";
}else {
echo "The password is incorrect";
}
Expected result:
----------------
I expect it to encrypt the password using crypt with the first 2 letters
of whatever username.
which it does
then when I go to retrieve it with the persons entered information, if
they typed the same password and username earlier, I expect it to get a
match on the password, but it doesn't
Actual result:
--------------
it doesn't match all the time, it does if it's right, if it's way off it
returns false, which is good, but if it's close to a match but a little
off it returns true
--
Edit bug report at http://bugs.php.net/?id=38152&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38152&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38152&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38152&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38152&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38152&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38152&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38152&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38152&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38152&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38152&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38152&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38152&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38152&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38152&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38152&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38152&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38152&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38152&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38152&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38152&r=mysqlcfg