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!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
Basically, Im using the following code for a simple project that I've been messing around with. It does what I need it to do in terms of allowing the user to register etc. Now I want to look at validatation and security.
<div id="content">
<?php
// Check if he wants to register:
if (!empty($_POST[username]))
{
// Check if passwords match.
if ($_POST[password] != $_POST[password2])
exit("Error - Passwords don't match. Please go back and try again.");
require_once("connect.php");
//$password = md5($password);
// Register him.
$query = mysql_query("INSERT INTO members
(username, firstname, lastname, password)
VALUES ('$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[password]')")
or die ("Error - Couldn't register user.");
echo "Congratulations $_POST[username]! You've successfully registered!<br /><br />
Please continue to the <a href='login.php'><b>login</b></a> page in order to access all of the wonderful members features.";
exit();
}
?>
<form action="register.php" method="post">
<table width="75%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><label>Desired Username: <input type="text" name="username" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><label>First Name: <input type="text" name="firstname" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><label>Last Name: <input type="text" name="lastname" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name= "password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><label>Verify Password: <input type="password" name="password2" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Register"></td>
</tr>
</table>
</form>
</div>
What I need to do is use the MD5 function to encrypt the database passwords. It's probably quite simple but Ive tried a couple of methods and havent managed to get it working yet. Any help is greatly appreciated. Thanks
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
Papa - I've implemented your suggestion, yes it works in terms of that it encrypts the password within the database and still allows the user to register, however, it will not let me login with the newly created account.
<?php $query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or header("location: http://localhost/dbmodule/login.php"); ?>
Im assuming that I'll need to change the password = ' ' part on the login, but what would I need to change that too?