Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/14715-perl-to-php/
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.
Link to comment
https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58799
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 '/'.
Link to comment
https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58840
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]
Link to comment
https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58865
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
Link to comment
https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-59097
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.