Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2005, 08:34 PM   PM User | #1
floydus
New to the CF scene

 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
floydus is an unknown quantity at this point
Javascript to php conversion wanted

I need, at work to convert the following functions to php...
I tried, but I don't get the same result...
Please Gurus!!!
Thanks.

<script type="text/javascript">
<!--
/* --- private --- */
function Login()
{
var Ret = true;

if((document.all("txtUser").value).length > 0)
{
if(document.all("txtPassword").value != "")
{
Ret = CheckComValue(document.all("txtPassword").value);
}

if(CheckComValue(document.all("txtUser").value) && (Ret != false))
{
var strKey = "%#000500";
var strUser = Encryption(document.all("txtUser").value, strKey, 32);
var strPass = Encryption(document.all("txtPassword").value, strKey, 32);
var strURL = "./ulogin.cgi?USER=" + strUser + "&PASS=" + strPass + "&KEY=" + strKey + RetTempParam();
window.open(strURL, "_self", "menubar=no,status=yes,width=1024,height=768,left=0,top=0");

}
else
{
alert("[User Name/Password] Input character is incorrect.");
}
}
}

function RetTempParam()
{
var cdtNow = new Date();
var strRet = "&TEMP=" + cdtNow.getTime();

return strRet;
}

function CheckComValue(strParam)
{
var strBaseChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

var bRet = true;
var iParamLen = strParam.length;

for (var iIndex = 0; iIndex < iParamLen; iIndex++)
{
if (strBaseChar.indexOf(strParam.charAt(iIndex)) == -1)
{
bRet = false;
break;
}
}

return bRet;
}

function Encryption(strInput, strKey, iSize)
{
var strCode = new Array;

for (i=0 ;i < iSize ;i++)
{

if (i < strInput.length)
{
asciiCode = strInput.charCodeAt(i);

}
else
{
asciiCode = 0;

}

if (i != 0 )
{
asciiCode ^= maskCode;

}

for (j=0 ;j < (strKey.length) ;j++)
{
asciiKey =strKey.charCodeAt(j);

asciiCode = (asciiCode ^ asciiKey) - asciiKey;

}
maskCode = asciiCode & 0xFF;

hexCode = maskCode.toString(16);

if (maskCode < 16)
{
strCode += "0";
}
strCode += String(hexCode);
}
return strCode;
}

//-->
</script>

here is my try....
PHP below..............


<?php
function CheckComValue($strParam)
{
$strBaseChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$bRet = true;
$iParamLen = strlen($strParam);
for ($iIndex = 0; $iIndex < $iParamLen; $iIndex++)
{
$pos=strrpos($strBaseChar, substr($strParam, $iIndex, 1));
if($pos === false)
$bRet = false;
}
return $bRet;
}
function hexstr($hex)
{
$string="";
for ($i=0;$i<strlen($hex)-1;$i+=2)
$string.=chr(hexdec($hex[$i].$hex[$i+1]));
return $string;
}

function Encryption($strInput, $strKey, $iSize)
{ $nbArray=0;
$strCode= array();
echo $strInput;
for ($i=0 ;$i < $iSize ;$i++)
{
if($i < strlen($strInput))
{
$asciiCode = ord(substr($strInput,$i,1));
}
else
{
$asciiCode = 0;
}

if ($i != 0 )
{
$asciiCode = $asciiCode ^ $maskCode;
echo $asciiCode."\n";
}

for ($j=0 ;$j < strlen($strKey) ;$j++)
{
$asciiKey =substr($strKey, $j, 1);
$asciiCode = ($asciiCode ^ $asciiKey) - $asciiKey;
}
$maskCode = $asciiCode & 0xFF;
$hexCode = hexstr($maskCode);

if ($maskCode < 16)
{
$strCode[$nbArray++] = "0";
}
$strCode[$nbArray++] = $hexCode;
}
$strCodestr="";
for ($i =0; $i < sizeof($strCode); $i++) {
$strCodestr = $strCodestr.$strCode[$i];
}
return $strCodestr;
}
echo Encryption("ADMIN", "105634", 32);
?>
floydus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:41 AM.


Advertisement
Log in to turn off these ads.