PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 1:37 pm
Code: Select all
<?php
// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
$mess0 = "<center><font color=black size=3>You must enter a password to login.</font></a></center>";
$mess1 = "<center><font color=black size=3>You must enter a name to login.</font></a></center>";
$mess2 = "<center><font color=black size=3>That account or password is invalid.</font></a></center>";
if(!$sp) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!$perm) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!file_exists("members/".$sp.".htm")) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} else {
function bytexor($a,$b,$l)
{
$c="";
for($i=0;$i<$l;$i++) {
$c.=$a{$i}^$b{$i};
}
return($c);
}
function binmd5($val)
{
return(pack("H*",md5($val)));
}
function decrypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=$m=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
}
function crypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
}
$crypted = crypt_md5($message, $key);
if($fp==$crypted) {
header("Location:main.php");
fclose($fp);
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.php'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
heres my script, for login... I can't seem to get it to work properly, where did I go wrong with my syntax??? Im trying to read a file and compare the md5 encryption with the pass which is to also be encrypted and used to compare with what was encrypted when the user joined... can someone please take a look at this for me... thanks in advance
feyd | use
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 1:49 pm
which line is 82?
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 1:54 pm
I altered the script, after I posted it, and now the error is on line 75 which is the line after the ?>... there is no code on line 75... what's wrong with my script...??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 1:57 pm
you're not closing all the if..else junk..
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 2:05 pm
like where... it looks like I did???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 2:07 pm
Code: Select all
if(!$sp) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!$perm) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!file_exists("members/".$sp.".htm")) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} else {
the last else there is never closed.
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 2:35 pm
got it closed up now, but now it's saying a call to undefined function:
Code: Select all
<?php
// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
$mess0 = "<center><font color=black size=3>You must enter a password to login.</font></a></center>";
$mess1 = "<center><font color=black size=3>You must enter a name to login.</font></a></center>";
$mess2 = "<center><font color=black size=3>That account or password is invalid.</font></a></center>";
if(!$sp) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess0."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!$perm) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess1."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} elseif(!file_exists("members/".$sp.".htm")) {
echo "<center><font size=6>What Happened?</font></center><br><br>";
echo "<center><div style='border:#000000 1px solid; width:200;'>".$mess2."</div></center>";
echo "<br><br><center><a href='#' style='text-decoration:none'><font size=2 color=white>back</font></a></center>";
} else {
function bytexor($a,$b,$l)
{
$c="";
for($i=0;$i<$l;$i++) {
$c.=$a{$i}^$b{$i};
}
return($c);
}
function binmd5($val)
{
return(pack("H*",md5($val)));
}
function crypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
} }
$crypted = crypt_md5($message, $key); //here's the error
$fx = fopen($sp.".txt","r");
$fx = readfile($sp.".txt");
$str = $crypted;
if($perm==$str) {
header("Location:main.php");
fclose($fx);
exit;
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.php'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
i am trying to read a txt file, which holds an encrypted pass, then I want to compare that pass, to the input the user submits, which should be encrypted as well, before, the script goes to compare the input to the stored value, which came from when the user signed up... can someone please, please, fix this script to work... please
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 2:42 pm
well.. those 3 functions will only exist when that else which holds them is run..
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 2:50 pm
my if statement checks if the user inputted a name, if so then it checks if they entered a pass, and then finally it checks to see if that username, exists.. if exists, then it proceeds to the validate the user input, if not it echos invalid username or password... I tested this with signup.php, and then tried to login and it says that the function I described in my post above, is undefined... could there be anyother reasons why this isnt working, I mean can you look at this script and call it solid code? thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 2:58 pm
this is the entirity of your else as it stood in your last code post:
Code: Select all
} else {
function bytexor($a,$b,$l)
{
$c="";
for($i=0;$i<$l;$i++) {
$c.=$a{$i}^$b{$i};
}
return($c);
}
function binmd5($val)
{
return(pack("H*",md5($val)));
}
function crypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
} }
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 3:13 pm
Code: Select all
<?php
// check if pass is correct
$sp = $_GET['name'];
$perm = $_GET['pass'];
function bytexor($a,$b,$l)
{
$c="";
for($i=0;$i<$l;$i++) {
$c.=$a{$i}^$b{$i};
}
return($c);
}
function binmd5($val)
{
return(pack("H*",md5($val)));
}
function crypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
}
$crypted = crypt_md5($message, $key);
$fx = fopen($sp.".txt","r");
$fx = readfile($sp.".txt");
exit;
if($crypted==$perm) {
echo "correct";
} else {
echo "<center><font size=2 color=black>Invalid Login.</font></center><br><br>";
echo "<center><a href='login.htm'><font size=1 color=black>Re-Try</font></a></center>";
}
?>
for the sake of making this easy... I took out the else crap... now look at the chunk of code that compares input with stored data... this is not echoing correct... even when the correct pass is put in, plus I dont even think the input is being md5'd... feyd, is this script missing anything, I mean, I have never done this before today, and am totally winging this whole PHP thing, especially the PHP login schema... Im trying to learn man, so, could you just give me a push in the right direction, please... thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jul 01, 2004 3:24 pm
you do that an exit; in there...
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Thu Jul 01, 2004 3:49 pm
duh, yeah that might help... thought you had to exit for some reason... only after you open and close dir and files... right??? anyway, now the darn thing is saying every password is correct...lol, ahhh this is killin me... i knew it wasnt md5in the input... any help with that?