Jump to content

Archived

This topic is now archived and is closed to further replies.

Branden Wagner

Perl to PHP

Recommended Posts

I need some help, i am trying to convert everything i have into PHP... currently i have it in JSP,Perl,PHP,.... and anything else you might think of, ive run into a small problem with crypt.... i was wondering if any one could help me.

the Perl version:
[code]
#!/usr/bin/perl

if( $#ARGV != 0 )
{
  print "usage: vcrypt password\n";
  exit 1;
}
my $salt = join '', ('.', '/', 0..9,'A'..'Z', 'a'..'z')[rand 64, rand 64];
print crypt($ARGV[0], $salt) ."\n";
[/code]

how would i write the same thing in PHP??
Would i just have to use
[code]crypt($password);[/code]
without a salt? or would i need to continue to specify that specific salt, and how would PHP accept that?

any help would be greatful.
-Branden

Share this post


Link to post
Share on other sites
Anyone?? anyone understand perl? if not i can explain what it needs to do in english, if you can help me put it in php
PLEASE help me.... Thank you.

Share this post


Link to post
Share on other sites
a description would help, yes.  i assume that $salt ends up being a string of random alphanum+/+. characters, 64 characters long?  what does crypt() then do with the salt?

Share this post


Link to post
Share on other sites
well in perl you can use the "crypt" function and similar to php you can "salt" the string to be crypted
basically telling the function what can be used (character wise) to crypt the password in this case
the ones mentioned previously.
i see that with the crypt function i can

[code]crypt($password , $salt); [/code]

but it doesnt accept the same salt string, like perl does.

Share this post


Link to post
Share on other sites
assuming the salt is just a string containing all the characters you specified, you'd use:

[code]$salt = implode('', array_merge(array('.'), array('/'), range(0, 9), range('a', 'z'), range('A', 'Z')));[/code]

Share this post


Link to post
Share on other sites
I don't know perl either but... php has a crypt function and if you don't supply a salt one will be generated for you. looks to me like perl is just creating a random salt???

Share this post


Link to post
Share on other sites
[code]join '', ('.', '/', 0..9,'A'..'Z', 'a'..'z')[rand 64, rand 64];[/code]

., /, the range 0-9, the range A-Z, and the range a-z are within a list () and make up 64 characters. The list is being sliced [] with two random indexes. For example, [0, 1] would give you '.' and '/'.

Share this post


Link to post
Share on other sites
right i understand what the perl is doing, but i need to generate the same salt for the php crypt function.. so how would i do that?

[code]
crypt($password, ./[0-9A-Za-Z][rand 64,rand 64])
[/code]

that doesnt work...so what am i doing wrong?

Share this post


Link to post
Share on other sites
This isn't [i]exactly[/i] what it's doing (code for code), but same difference--getting two random values from the array.

[code]<?php

$array = array(
'.',
'/',
);
$array = array_merge(
$array,
range(0, 9),
range('A', 'Z'),
range('a', 'z')
);

shuffle($array);
echo $salt = array_pop($array) . array_shift($array);

?>[/code]

Share this post


Link to post
Share on other sites
well i feel kinda stupid...

This doesnt work:
[code]
crypt($password, ./[0-9A-Za-Z][rand 64,rand 64])
[/code]

This does:
[code]
crypt($password, "./[0-9A-Za-Z][rand 64,rand 64]")
[/code]

all i missed were the freakin quotes, guess thats what happens when you spend too much time infront of the computer

Share this post


Link to post
Share on other sites
The string "./[0-9A-Za-Z][rand 64,rand 64]" is the salt though. The rand's are not actually being calculated, nor are the ranges taking effect.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.