Login...
Posted: Fri Jul 16, 2010 4:27 pm
Hi there! ;p
this is my first post here!
This is my second day of trying out PHP, and so far I love it.
Though, I did not like playing around with the databases this early... *Shivers from all the errors*
Ok, so I made a php script that registers you and converts the password into md5. THat wasn't a probleme at all... but the login part... now that was something different!
That's the code. You'll have to excuse me if it's NOT correct at all xD. Also, I did some reading about md5 encoding... It says it's impossible to decode, how on earth would it know what encrypted password is correct? :s
Thanks.
Sincerely,
Zach.
this is my first post here!
Though, I did not like playing around with the databases this early... *Shivers from all the errors*
Ok, so I made a php script that registers you and converts the password into md5. THat wasn't a probleme at all... but the login part... now that was something different!
Code: Select all
<?php
$username = str_replace("'","''",$_GET["un"]);
$password = md5($_GET["pw"]);
$host="X";
$un="X";
$pw="X";
$con = mysql_connect($host,$un,$pw);
if(!$con) {
die("Could not connect!" . mysql_error());
}
mysql_select_db("Users",$con);
$pw = md5($_GET['pw']);
$r1 = mysql_query("SELECT * FROM Users WHERE un = '$_GET[un]'");
$r2 = mysql_query("SELECT * FROM Users WHERE pw = '$password'");
if(mysql_fetch_array($r1) && mysql_fetch_array($r2)) {
echo("Correct login!");
}
if(!mysql_fetch_array($r1)) {
echo("Incorrect login!");
}
elseif(!mysql_fetch_array($r2)) {
echo("Incorrect password!");
}
?>Thanks.
Sincerely,
Zach.