Ask a Question related to PHP Development, Design and Development.
-
Lars Plessmann #1
crypt function in PHP different from Perl's crypt?
Why returns the crypt function a longer strin than Perls crypt?
I need the same length (8 chars) for a password field link its used in
the .htpasswd files of apache.
In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
instead of "Td2.gm2."
Why?
are there any parameters for crypt, to get only the neccesairy part?
thanks a lot,
Lars
Lars Plessmann Guest
-
Crypt::DH Crypt::Random install problem
The Linux Test Project (ltp http://ltp.sourceforge.net/) perl file autoltp requires Net::SSH and Net::SFTP These ultimately require Crypt::DH which... -
#26131 [Opn->Bgs]: the crypt function have no MD5 support
ID: 26131 Updated by: didou@php.net Reported By: yoda at cef dot org dot tw -Status: Open +Status: ... -
#26131 [Opn]: the crypt function have no MD5 support
ID: 26131 User updated by: yoda at cef dot org dot tw Reported By: yoda at cef dot org dot tw Status: Open Bug... -
#26131 [NEW]: the crypt function have no MD5 support
From: yoda at cef dot org dot tw Operating system: RedHat Linux 9.0 PHP version: 4.3.4 PHP Bug Type: *Compile Issues Bug... -
note 33705 added to function.crypt
there is no passwordgenerator available in php, so i thought i would present mine in here.... Its just a simple function which you could change how... -
Shane Lahey #2
Re: crypt function in PHP different from Perl's crypt?
this probably has to do with the user supplied salt your giving.... ??
either that or CRYPT_STD_DES is unsupported on your server???
to check if your system supports it, first try:
<?php
if (CRYPT_STD_DES == 1)
echo "Standard DES-based encryption is supported\n";
else echo "Error: Standard DES-based encryption is not supported\n";
?>
Information about crypt() is located at
[url]http://ca2.php.net/manual/en/function.crypt.php[/url]
The standard DES-based encryption crypt() returns the salt as the
first two characters of the output. It also only uses the first eight
characters of str , so longer strings that start with the same eight
characters will generate the same result (when the same salt is used).
On systems where the crypt() function supports multiple encryption
types, the following constants are set to 0 or 1 depending on whether
the given type is available:
CRYPT_STD_DES - Standard DES-based encryption with a two character
salt
CRYPT_EXT_DES - Extended DES-based encryption with a nine character
salt
CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
$1$
CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
starting with $2$
Note: There is no decrypt function, since crypt() uses a one-way
algorithm.
On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
<Lars.Plessmann@gmx.de> wrote:
>Why returns the crypt function a longer strin than Perls crypt?
>I need the same length (8 chars) for a password field link its used in
>the .htpasswd files of apache.
>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>instead of "Td2.gm2."
>
>Why?
>
>are there any parameters for crypt, to get only the neccesairy part?
>
>
>thanks a lot,
>
>LarsShane Lahey Guest
-
Lars Plessmann #3
Re: crypt function in PHP different from Perl's crypt?
Shane Lahey wrote:
Hi!> this probably has to do with the user supplied salt your giving.... ??
> either that or CRYPT_STD_DES is unsupported on your server???
>
> to check if your system supports it, first try:
>
> <?php
> if (CRYPT_STD_DES == 1)
> echo "Standard DES-based encryption is supported\n";
> else echo "Error: Standard DES-based encryption is not supported\n";
> ?>
>
>
>
> Information about crypt() is located at
> [url]http://ca2.php.net/manual/en/function.crypt.php[/url]
>
>
> The standard DES-based encryption crypt() returns the salt as the
> first two characters of the output. It also only uses the first eight
> characters of str , so longer strings that start with the same eight
> characters will generate the same result (when the same salt is used).
>
> On systems where the crypt() function supports multiple encryption
> types, the following constants are set to 0 or 1 depending on whether
> the given type is available:
>
> CRYPT_STD_DES - Standard DES-based encryption with a two character
> salt
>
> CRYPT_EXT_DES - Extended DES-based encryption with a nine character
> salt
>
> CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
> $1$
>
> CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
> starting with $2$
>
> Note: There is no decrypt function, since crypt() uses a one-way
> algorithm.
>
>
>
> On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
> <Lars.Plessmann@gmx.de> wrote:
>
>>>>Why returns the crypt function a longer strin than Perls crypt?
>>I need the same length (8 chars) for a password field link its used in
>>the .htpasswd files of apache.
>>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>>instead of "Td2.gm2."
>>
>>Why?
>>
>>are there any parameters for crypt, to get only the neccesairy part?
>>
>>
>>thanks a lot,
>>
>>Lars
>
thanks.
I get the "Standard DES-based encryption is supported" message.
Thats the "short" string tells the documentation. But it isn't!
I don't enter the salt parameter, so it should use a random 2 character
string that delivers me a CRYPT_STD_DES crypt string.
But why do I get the long password?
In perl I get with the same apache the 8 character passwortd string
without any "$" prefixes.
Lars Plessmann Guest
-
shortbackandsides.no@spam.hairdresser.net #4
Re: crypt function in PHP different from Perl's crypt?
Although the returned string is longer than that from using Perl to
generate a password, it may not matter.
You say it is for use in an .htpasswd file.
..htpasswd appears to work OK with either short or long passwords, I
have one which includes some of both types in it like this:
user1:$1$hSbU8fhz$vk.jwLUCx2AQSgqMpjpjR0
user2:1HH/7oEU7wTkY
I can log on OK as either user1 or user2 so whilst it is interesting
to understand why PHP is giving a longer result it may not matter once
you come to use it.
Or have I misunderstood something?
On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
<Lars.Plessmann@gmx.de> wrote:
>Why returns the crypt function a longer strin than Perls crypt?
>I need the same length (8 chars) for a password field link its used in
>the .htpasswd files of apache.
>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>instead of "Td2.gm2."
>
>Why?
>
>are there any parameters for crypt, to get only the neccesairy part?
>
>
>thanks a lot,
>
>Larsshortbackandsides.no@spam.hairdresser.net Guest
-
Shane Lahey #5
Re: crypt function in PHP different from Perl's crypt?
i'll be damned, you need to pass a 2 char salt to get a DES crypt()
...... here's a simple solution simply call: des_crypt([password]).....
<?php
returns a completely random character from the $asc string.
function random_ch()
{
$asc =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789./';
list($usec, $sec) = explode(' ', microtime());
mt_srand((float) $sec + ((float) $usec * 100000));
return $asc[ (mt_rand() % strlen($asc)) ];
}
// return a DES encrypted $pass using a random 2char salt.
function des_crypt($pass)
{
$salt = random_ch() . random_ch();
return crypt($pass, random_ch);
}
?>
On Wed, 26 May 2004 08:45:53 +0200, Lars Plessmann
<Lars.Plessmann@gmx.de> wrote:
>Shane Lahey wrote:
>>>> this probably has to do with the user supplied salt your giving.... ??
>> either that or CRYPT_STD_DES is unsupported on your server???
>>
>> to check if your system supports it, first try:
>>
>> <?php
>> if (CRYPT_STD_DES == 1)
>> echo "Standard DES-based encryption is supported\n";
>> else echo "Error: Standard DES-based encryption is not supported\n";
>> ?>
>>
>>
>>
>> Information about crypt() is located at
>> [url]http://ca2.php.net/manual/en/function.crypt.php[/url]
>>
>>
>> The standard DES-based encryption crypt() returns the salt as the
>> first two characters of the output. It also only uses the first eight
>> characters of str , so longer strings that start with the same eight
>> characters will generate the same result (when the same salt is used).
>>
>> On systems where the crypt() function supports multiple encryption
>> types, the following constants are set to 0 or 1 depending on whether
>> the given type is available:
>>
>> CRYPT_STD_DES - Standard DES-based encryption with a two character
>> salt
>>
>> CRYPT_EXT_DES - Extended DES-based encryption with a nine character
>> salt
>>
>> CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
>> $1$
>>
>> CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
>> starting with $2$
>>
>> Note: There is no decrypt function, since crypt() uses a one-way
>> algorithm.
>>
>>
>>
>> On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
>> <Lars.Plessmann@gmx.de> wrote:
>>
>>>>>>>Why returns the crypt function a longer strin than Perls crypt?
>>>I need the same length (8 chars) for a password field link its used in
>>>the .htpasswd files of apache.
>>>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>>>instead of "Td2.gm2."
>>>
>>>Why?
>>>
>>>are there any parameters for crypt, to get only the neccesairy part?
>>>
>>>
>>>thanks a lot,
>>>
>>>Lars
>>
>Hi!
>
>thanks.
>I get the "Standard DES-based encryption is supported" message.
>Thats the "short" string tells the documentation. But it isn't!
>I don't enter the salt parameter, so it should use a random 2 character
>string that delivers me a CRYPT_STD_DES crypt string.
>
>But why do I get the long password?
>In perl I get with the same apache the 8 character passwortd string
>without any "$" prefixes.Shane Lahey Guest
-
Lars Plessmann #6
Re: crypt function in PHP different from Perl's crypt?
[email]shortbackandsides.no@spam.hairdresser.net[/email] wrote:
I don't want to reserve so much fields for the password in the database.> Although the returned string is longer than that from using Perl to
> generate a password, it may not matter.
>
> You say it is for use in an .htpasswd file.
>
> .htpasswd appears to work OK with either short or long passwords, I
> have one which includes some of both types in it like this:
>
> user1:$1$hSbU8fhz$vk.jwLUCx2AQSgqMpjpjR0
> user2:1HH/7oEU7wTkY
>
> I can log on OK as either user1 or user2 so whilst it is interesting
> to understand why PHP is giving a longer result it may not matter once
> you come to use it.
>
> Or have I misunderstood something?
>
> On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
> <Lars.Plessmann@gmx.de> wrote:
>
>>>>Why returns the crypt function a longer strin than Perls crypt?
>>I need the same length (8 chars) for a password field link its used in
>>the .htpasswd files of apache.
>>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>>instead of "Td2.gm2."
>>
>>Why?
>>
>>are there any parameters for crypt, to get only the neccesairy part?
>>
>>
>>thanks a lot,
>>
>>Lars
>
So a 8 char password would be much better like the apache .htpasswd version.
Lars Plessmann Guest
-
Lars Plessmann #7
Re: crypt function in PHP different from Perl's crypt?
Shane Lahey wrote:
Well okay. this way brings me 13 char passwords. thats okay I think...> i'll be damned, you need to pass a 2 char salt to get a DES crypt()
>
> ..... here's a simple solution simply call: des_crypt([password]).....
>
> <?php
>
> returns a completely random character from the $asc string.
> function random_ch()
> {
> $asc =
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789./';
> list($usec, $sec) = explode(' ', microtime());
> mt_srand((float) $sec + ((float) $usec * 100000));
> return $asc[ (mt_rand() % strlen($asc)) ];
> }
>
>
> // return a DES encrypted $pass using a random 2char salt.
> function des_crypt($pass)
> {
> $salt = random_ch() . random_ch();
> return crypt($pass, random_ch);
> }
>
> ?>
>
>
>
>
> On Wed, 26 May 2004 08:45:53 +0200, Lars Plessmann
> <Lars.Plessmann@gmx.de> wrote:
>
>>>>Shane Lahey wrote:
>>
>>>>Hi!>>>this probably has to do with the user supplied salt your giving.... ??
>>>either that or CRYPT_STD_DES is unsupported on your server???
>>>
>>>to check if your system supports it, first try:
>>>
>>><?php
>>>if (CRYPT_STD_DES == 1)
>>> echo "Standard DES-based encryption is supported\n";
>>>else echo "Error: Standard DES-based encryption is not supported\n";
>>>?>
>>>
>>>
>>>
>>>Information about crypt() is located at
>>>[url]http://ca2.php.net/manual/en/function.crypt.php[/url]
>>>
>>>
>>>The standard DES-based encryption crypt() returns the salt as the
>>>first two characters of the output. It also only uses the first eight
>>>characters of str , so longer strings that start with the same eight
>>>characters will generate the same result (when the same salt is used).
>>>
>>>On systems where the crypt() function supports multiple encryption
>>>types, the following constants are set to 0 or 1 depending on whether
>>>the given type is available:
>>>
>>>CRYPT_STD_DES - Standard DES-based encryption with a two character
>>>salt
>>>
>>>CRYPT_EXT_DES - Extended DES-based encryption with a nine character
>>>salt
>>>
>>>CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
>>>$1$
>>>
>>>CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
>>>starting with $2$
>>>
>>>Note: There is no decrypt function, since crypt() uses a one-way
>>>algorithm.
>>>
>>>
>>>
>>>On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
>>><Lars.Plessmann@gmx.de> wrote:
>>>
>>>
>>>
>>>>Why returns the crypt function a longer strin than Perls crypt?
>>>>I need the same length (8 chars) for a password field link its used in
>>>>the .htpasswd files of apache.
>>>>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>>>>instead of "Td2.gm2."
>>>>
>>>>Why?
>>>>
>>>>are there any parameters for crypt, to get only the neccesairy part?
>>>>
>>>>
>>>>thanks a lot,
>>>>
>>>>Lars
>>>
>>>
>>
>>thanks.
>>I get the "Standard DES-based encryption is supported" message.
>>Thats the "short" string tells the documentation. But it isn't!
>>I don't enter the salt parameter, so it should use a random 2 character
>>string that delivers me a CRYPT_STD_DES crypt string.
>>
>>But why do I get the long password?
>>In perl I get with the same apache the 8 character passwortd string
>>without any "$" prefixes.
>
So, I will do it in this way!
thanks a lot, Shane!
-Lars
Lars Plessmann Guest
-
Shane Lahey #8
Re: crypt function in PHP different from Perl's crypt?
>
just so you know... the MD5 hashed passwords are MUCH more secure than>I don't want to reserve so much fields for the password in the database.
>So a 8 char password would be much better like the apache .htpasswd version.
the DES encrypted passwords, so using the longer passwords would make
cracking passwords much much harder if your database were ever
comprimised... sometimes the few extra bytes are just worth it :D
Shane Lahey Guest
-
Lars Plessmann #9
Re: crypt function in PHP different from Perl's crypt?
Shane Lahey wrote:
Oh it doesn't work, because password A and password B are now not equal.> i'll be damned, you need to pass a 2 char salt to get a DES crypt()
>
> ..... here's a simple solution simply call: des_crypt([password]).....
>
> <?php
>
> returns a completely random character from the $asc string.
> function random_ch()
> {
> $asc =
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789./';
> list($usec, $sec) = explode(' ', microtime());
> mt_srand((float) $sec + ((float) $usec * 100000));
> return $asc[ (mt_rand() % strlen($asc)) ];
> }
>
>
> // return a DES encrypted $pass using a random 2char salt.
> function des_crypt($pass)
> {
> $salt = random_ch() . random_ch();
> return crypt($pass, random_ch);
> }
>
> ?>
>
>
>
>
> On Wed, 26 May 2004 08:45:53 +0200, Lars Plessmann
> <Lars.Plessmann@gmx.de> wrote:
>
>>>>Shane Lahey wrote:
>>
>>>>Hi!>>>this probably has to do with the user supplied salt your giving.... ??
>>>either that or CRYPT_STD_DES is unsupported on your server???
>>>
>>>to check if your system supports it, first try:
>>>
>>><?php
>>>if (CRYPT_STD_DES == 1)
>>> echo "Standard DES-based encryption is supported\n";
>>>else echo "Error: Standard DES-based encryption is not supported\n";
>>>?>
>>>
>>>
>>>
>>>Information about crypt() is located at
>>>[url]http://ca2.php.net/manual/en/function.crypt.php[/url]
>>>
>>>
>>>The standard DES-based encryption crypt() returns the salt as the
>>>first two characters of the output. It also only uses the first eight
>>>characters of str , so longer strings that start with the same eight
>>>characters will generate the same result (when the same salt is used).
>>>
>>>On systems where the crypt() function supports multiple encryption
>>>types, the following constants are set to 0 or 1 depending on whether
>>>the given type is available:
>>>
>>>CRYPT_STD_DES - Standard DES-based encryption with a two character
>>>salt
>>>
>>>CRYPT_EXT_DES - Extended DES-based encryption with a nine character
>>>salt
>>>
>>>CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
>>>$1$
>>>
>>>CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
>>>starting with $2$
>>>
>>>Note: There is no decrypt function, since crypt() uses a one-way
>>>algorithm.
>>>
>>>
>>>
>>>On Wed, 26 May 2004 00:40:42 +0200, Lars Plessmann
>>><Lars.Plessmann@gmx.de> wrote:
>>>
>>>
>>>
>>>>Why returns the crypt function a longer strin than Perls crypt?
>>>>I need the same length (8 chars) for a password field link its used in
>>>>the .htpasswd files of apache.
>>>>In php i retrieve a string like "$1$Td2.gm2.$cqiXCn3YKNANp4Q64Vvkf0"
>>>>instead of "Td2.gm2."
>>>>
>>>>Why?
>>>>
>>>>are there any parameters for crypt, to get only the neccesairy part?
>>>>
>>>>
>>>>thanks a lot,
>>>>
>>>>Lars
>>>
>>>
>>
>>thanks.
>>I get the "Standard DES-based encryption is supported" message.
>>Thats the "short" string tells the documentation. But it isn't!
>>I don't enter the salt parameter, so it should use a random 2 character
>>string that delivers me a CRYPT_STD_DES crypt string.
>>
>>But why do I get the long password?
>>In perl I get with the same apache the 8 character passwortd string
>>without any "$" prefixes.
>
The same passwords encrypred with the des_crypt() function do not
concur. whats the problem?
by the way, I changed
to> $salt = random_ch() . random_ch();
> return crypt($pass, random_ch);
$salt = random_ch() . random_ch();
return crypt($pass, $salt);
I think it was that what you meant?
I hope you can help?
Lars
Lars Plessmann Guest
-
Shane Lahey #10
Re: crypt function in PHP different from Perl's crypt?
On Wed, 26 May 2004 23:55:07 +0200, Lars Plessmann
<Lars.Plessmann@gmx.de> wrote:
hehe, simple>Oh it doesn't work, because password A and password B are now not equal.
>The same passwords encrypred with the des_crypt() function do not
>concur. whats the problem?
>
>by the way, I changed
>>> > $salt = random_ch() . random_ch();
> > return crypt($pass, random_ch);
>to
>
> $salt = random_ch() . random_ch();
> return crypt($pass, $salt);
>
>
>I think it was that what you meant?
>
>I hope you can help?
>
>
>Lars
it's because the seed is random.
you will need to seed the provided password with the first two letters
of the stored password
.....
easier for me to give an example
say you have a database with user MisterX and encrypted password
xZX3RQm9R4w3.
when checking if MisterX is providing the same password in the future
you will need to take the first two letters from the stored encrypted
password (in this case 'xZ') and use that as the salt to encrypt the
new password, then compare the two hashes..... DES encryption is a
ONE-WAY hash, it' can't exactally be de-crypted, just compared.
hope this makes sense....
For my example: xZX3RQm9R4w3. is the word 'password' crypt()'ed with
the seed 'xZ'
Shane Lahey Guest
-
Shane Lahey #11
Re: crypt function in PHP different from Perl's crypt? (0/1)
maybe this will be easier for u to use? (classes are always more fun)
:D
to use in your php script:
require_once('myenc.class.php');
// create a new instance of the MyENC class
$enc = new MyENC;
// to encrypt a string
$encoded = $enc->des_crypt('password');
// to check if 'password' is the same as $encoded (hope this makes
sense)
$same_as_encode = $enc->des_check('password', $encoded);
// destroy $enc if we are finished with it :D
unset($enc);
Shane Lahey Guest



Reply With Quote

