Branden Wagner Posted July 15, 2006 Share Posted July 15, 2006 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/perlif( $#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 Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/ Share on other sites More sharing options...
Branden Wagner Posted July 15, 2006 Author Share Posted July 15, 2006 Anyone?? anyone understand perl? if not i can explain what it needs to do in english, if you can help me put it in phpPLEASE help me.... Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58724 Share on other sites More sharing options...
akitchin Posted July 16, 2006 Share Posted July 16, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58730 Share on other sites More sharing options...
Branden Wagner Posted July 16, 2006 Author Share Posted July 16, 2006 well in perl you can use the "crypt" function and similar to php you can "salt" the string to be cryptedbasically telling the function what can be used (character wise) to crypt the password in this casethe 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. Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58799 Share on other sites More sharing options...
akitchin Posted July 16, 2006 Share Posted July 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58824 Share on other sites More sharing options...
Drumminxx Posted July 16, 2006 Share Posted July 16, 2006 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??? Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58828 Share on other sites More sharing options...
effigy Posted July 16, 2006 Share Posted July 16, 2006 [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 '/'. Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58840 Share on other sites More sharing options...
Branden Wagner Posted July 16, 2006 Author Share Posted July 16, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58846 Share on other sites More sharing options...
effigy Posted July 16, 2006 Share Posted July 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-58865 Share on other sites More sharing options...
Branden Wagner Posted July 16, 2006 Author Share Posted July 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-59097 Share on other sites More sharing options...
effigy Posted July 17, 2006 Share Posted July 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14715-perl-to-php/#findComment-59595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.