Forum Moderators: coopster

Message Too Old, No Replies

Regisration and login form help.

         

bodycount

2:29 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



I have made a html/php regstration form which work, but i dont now if this is the right way of doing it.

-----------------------------------------------------------

html registration form

-----------------------------------------------------------

<html>
<body>
<link rel="stylesheet" href="http://www.************.co.uk/********.css">
<center><b>Please Input Your Username, Password and Email Address</b>
<form method="POST" action="register_add.php">
<table>
<tr><td align=right><b><font size=-1>Enter Username : </td><td><b><font size=-1><input type=text name="USERNAME"></td></tr>
<tr><td align=right><b><font size=-1>Enter Password : </td><td><b><font size=-1><input type=password name="PASSWORD"></td></tr>
<tr><td align=right><b><font size=-1>Re-Enter Password : </td><td><b><font size=-1><input type=password name="PASSWORD2"></td></tr>
<tr><td><b><font size=-1>Enter a Valid Email Address :</td><td><b><font size=-1><input type=text name="EMAILADD"></td></tr>
<tr><td align=right><b><font size=-1>Re-Enter Email Address : </td><td><b><font size=-1><input type=text name="EMAILADD2"></td></tr>
<tr><td><input type="submit" value="Register Me"></td><td><input type="reset" value="Start Again"></td></tr>
</table>
</form>
</center>
</body>
</html>

-----------------------------------------------------------

php which passes the info to the database

-----------------------------------------------------------

<link rel="stylesheet" href="http://www.**********.co.uk/********.css">
<?php

include ("connection.php");

echo "<center><b>Registration Form</b></center>";

$error=false;

$pass_error=false;

$email_error=false;

if (($USERNAME == "") ¦¦ ($PASSWORD == "") ¦¦ ($EMAILADD == "") ¦¦ ($PASSWORD2 == "") ¦¦ ($EMAILADD2 == "") )
{
$error=true;
}
if ($PASSWORD!= $PASSWORD2)
{
$pass_error=true;
}
if ($EMAILADD!= $EMAILADD2)
{
$email_error=true;
}
if ($error)
{
echo "<br>All fields need to be filled in";
}
if ($pass_error)
{
echo "<br>Both the password fields need to match";
}
if ($email_error)
{
echo "<br>Both the Email Address fields need to match";
}
if (($error) ¦¦ ($pass_error) ¦¦ ($email_error))
{
echo "<br>Back to the Registration <a href=\"register.php\">Form</a>";
exit;
}

$sql="INSERT INTO USERS (USERNAME,PASSWORD,EMAILADD) VALUES ('$USERNAME', MD5('$PASSWORD'),'$EMAILADD')";
$sql2="SELECT * FROM USERS WHERE USERNAME='$USERNAME' AND PASSWORD='$PASSWORD' AND EMAILADD='$EMAILADD'";

$mysql_result=mysql_query(sql2);
$num_rows=@mysql_num_rows($mysql_result);

if ( $num_rows!= 0)
{
echo "<br>USERNAME already in use, Please Choose another <a href=\"register.php\">Back</a>";
exit;
}
if (!mysql_query($sql))
{
echo "Error cannot add record..Retry";
echo "<br><a href=\"register.php\">Back</a>";
exit;
}
else
{
echo "Table updated [".mysql_affected_rows()."] record added<br>";
echo "Welcome Please make note of your details<br>";
echo "Username : <b>$USERNAME</b><br>Password : <b>$PASSWORD</b><br> Email Address : <b>$EMAILADD</b>";
echo "<br>You now need to <a href=\"loginpage.php\">LOGIN</a>";
}

?>

-----------------------------------------------------------

The info gets passed to the database and the password is encrypted, but how do i now use the info to login?

Twisted Mind

3:05 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



with another form :p and sessions dunnow how probaly a tut to find on inet anyway

dreamcatcher

3:35 pm on Nov 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The info gets passed to the database and the password is encrypted, but how do i now use the info to login?

When you process the form data, compare the hash to the one in the database.

//From form
$pass = $_POST['pass'];
$user = $_POST['user'];

//Query the DB
$query = mysql_query("SELECT USERNAME,PASSWORD FROM USERS WHERE USERNAME = '".md5($user)."' AND PASSWORD = '".md5($pass)."' LIMIT 1") or die(mysql_error());

if (mysql_num_rows($query)>0)
{
//ok
//register session data
}
else
{
//not ok
}

Hope that helps.

dc

bodycount

4:08 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



Thanks for the help. I am a complete newbie at php how do i go about implementing this into a form?

//From form
$pass = $_POST['pass'];
$user = $_POST['user'];

dreamcatcher

5:41 pm on Nov 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<form method="POST" action="page.php">
<input type="text" name="user"><br>
<input type="text" name="pass"><br>
<input type="submit" value="Login">
</form>

Access POST variables as I mentioned.

dc

bodycount

11:19 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



This is what I have done and it does not seem to work
------------------------------------------------------

login form

------------------------------------------------------
<html>
<body>
<link rel="stylesheet" href="http://www.clanore.co.uk/XeonStyle.css">
<center><b>Please Input Your Username, Password and Email Address</b>
<form method="POST" action="login3.php">
<table>
<tr><td align=right><b><font size=-1>Enter Username : </td><td><b><font size=-1><input type=text name="USERNAME"></td></tr>
<tr><td align=right><b><font size=-1>Enter Password : </td><td><b><font size=-1><input type=password name="PASSWORD"></td></tr>
<tr><td><input type="submit" value="LOG IN"></td></tr>
</table>
</form>
</center>
</body>
</html>

------------------------------------------------------

PHP

------------------------------------------------------

<?php

include ("connection.php");

$PASSWORD = $_POST['PASSWORD'];
$USERNAME = $_POST['USERNAME'];

//Query the DB
$sql = "SELECT USERNAME,PASSWORD FROM USERS WHERE USERNAME = '".md5($USERNAME)."' AND PASSWORD = '".md5($PASSWORD)."' LIMIT 1";
$mysql_result=mysql_query($sql) or die(mysql_error());

if (!mysql_query($sql))
{
echo "ok";
//register session data
}
else
{
echo "not ok";
}
?>
------------------------------------------------------
it always seems to drop down to the "not ok" bit any idears

dreamcatcher

8:30 am on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whether you are getting a result set back or not, the query will always be true, hence the reason your if is failing.

Try mysql_num_rows to see if any rows were returned.

if (mysql_num_rows($mysql_result)>0)
{
echo "OK";
}
else
{
echo "NOT OK";
}

dc

bodycount

9:32 am on Nov 26, 2005 (gmt 0)

10+ Year Member



I have put that code in, and i have also echo back the "$mysql_result" and this is what is returned "Resource id #4"

bodycount

4:30 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



I have also noticed the what is sent to the data base is different to what is stored in the data base.

-------------------------------------------------------

From my web page USERNAME and PASSWORD are md5 encoded

-------------------------------------------------------

Username : c165c74dd5bc1ce0b0498653d5b465e8
Password : f079b4d872e7d1415bace2a536f91407

-------------------------------------------------------

This is what it is stored as in the data base

-------------------------------------------------------

USERNAME : f34a14d72e6f6a2b836c3c68347c283b
PASSWORD : b99b7467c512b54c14673a7fdc78bd4c

I have just also noticed that when i register as a new person that both the encypted username and password are the same as another person already in the data base with completly different usernames and passwords how can this be?

bodycount

11:33 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



In the above post regarding the md5 encrypted USERNAME and PASSWORD I was using IE6 and that seems to be a problem. I have tried using mozilla and that seems to store the info into the data base correctly, but still I can not login.

Does anyone known why IE6 does not work right. and why I cant get my login page to work

Help please this is doing my nut in.

bodycount

9:18 am on Nov 28, 2005 (gmt 0)

10+ Year Member



Just tried this at work using IE6 and it is working (must be my home pc), But still can not get my login page to work.

bodycount

10:34 pm on Nov 28, 2005 (gmt 0)

10+ Year Member



OK I have got this to work now, It was down to my username and password fields being set to 20 and not to 32. As I found out that md5 needs to be 32.

How do I go about doing authentication on my web pages?

dreamcatcher

11:35 am on Nov 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry for not replying again, I only just got to Hong Kong.

Look into sessions for what you want. Try this thread for starters:
[webmasterworld.com...]

dc