29.08.2014, 14:42
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:
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;
?>