Num_Hash in PHP?
#1

If anyone is decent with PHP, how would I convert this stock into PHP?

I'm using it for a simple online user account system, I am not concerned with security, I would just like to know how to do it.

pawn Код:
stock num_hash(buf[])//Dutils.inc
 {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++) {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
 }
Reply
#2

PHP код:
function num_hash($buf)
{
  
$length strlen($buf);
  
$s1 1;
  
$s2 0;
  
  for (
$n=0;$n<$length;$n++) {
       
$s1 = ($s1 $buf[$n]) % 65521;
       
$s2 = ($s2 $s1) % 65521;
  }
  return (
$s2 << 16) + $s1;

P.S. I don't test this =)
Reply
#3

I tired this as a simple php login, and it didn't work. Either I am hashing it wrong with the function you have me, or the hash didn't work.

Anyone know what I did wrong:

pawn Код:
<?php
$password = '329384925';//This is the result from my script (later I will have it get this password from the ini- implemented now for testing).
function num_hash($buf)
{
  $length = strlen($buf);
  $s1 = 1;
  $s2 = 0;
   
  for ($n=0;$n<$length;$n++) {
       $s1 = ($s1 + $buf[$n]) % 65521;
       $s2 = ($s2 + $s1) % 65521;
  }
  return ($s2 << 16) + $s1;
}  


//session_start();
if (!isset($_SESSION['loggedIn'])) {
    $_SESSION['loggedIn'] = false;
}

if (isset($_POST['password']))
{
    if (num_hash($_POST['password']) == $password)
    {
        $_SESSION['loggedIn'] = true;
    }
    else
    {
        die ('Incorrect password');//Currently returns this when I enter the correct password.
    }
}

if (!$_SESSION['loggedIn']): ?>

<html><head><title>Login</title></head>
  <body>
    <p>You need to login:</p>
    <form method="post">
      Password: <input type="password" name="password"> <br />
      <input type="submit" name="submit" value="Login">
    </form>
  </body>
</html>

<?php
exit();
endif;
?>
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)