PHP Login System With MD5 Hashing [MySQL & PHP] [SESSIONS]

Started on the old forum in June 2009 · view the original in the archive · old links redirect here

2 replies · 13,126 views · started 17 years ago · 1 min read

3 participants
PiN2 Newbie · 1 posts #1

PHP Login System With MD5 Hashing [MySQL & PHP] [SESSIONS]

First we will need to create a user's table MYSQL Query:

CREATE  TABLE `user` ( `id` INT NOT  NULL  AUTO_INCREMENT  PRIMARY  KEY ,
 `username` TEXT NOT  NULL ,
 `password` TEXT NOT  NULL ) ENGINE  =  MYISAM

Now that we got the database made lets go to the config file. PHP: [config.php]

<?php
$host = "localhost"; //The Location of your MySQL server [Usually localhost]
$user = "root"; //The username to connect with
$pass = "pass"; //The password for the username
$data = "users"; //The name of the database

//DO NOT TOUCH ANYTHING BELOW
mysql_connect("$host", "$user", "$pass");
mysql_select_db("$data");
SESSION_START();
?>

Now we will move on to the register page PHP: [register.php]

<?php
//We have to get a connection
require("config.php");

if(!$_GET['act']){ //This checks ?act= in the URL to see if there is a registration being processed
//Start Making the form
echo("<form method='POST' action='$PHP_SELF?act=register'>
Username: <input type='text' name='username' /><br />
Password: <input type='password' name='password' /><br />
<input type='submit' value='Register!' />
</form");
//Now that the form is taken care of

} else if($_GET['act'] == "register"){
 //Lets check to make sure that no other users are registered as that username
$check = mysql_query("SELECT * FROM `users` WHERE `username` = '{$_POST['username']}'");
if(mysql_num_rows($check) > 0){
//there is a user already registered
echo("That username is already taken!");
} else {
//There isn't a username
 mysql_query("INSERT INTO `user` (`id` ,`username` ,`password`) VALUES (NULL , '{$_POST['username']}', MD5( '{$_POST['password']}' ))");
echo("You have been registered!");
}

?>

Ok now lets move on to the login PHP: [login.php]

<?php
//We have to get a connection
 require("config.php");
 
 if(!$_GET['act']){ //This checks ?act= in the URL to see if there is a login being processed
 //Start Making the form
 echo("<form method='POST' action='$PHP_SELF?act=login'>
 Username: <input type='text' name='username' /><br />
 Password: <input type='password' name='password' /><br />
 <input type='submit' value='Login!' />
 </form");
 //Now that the form is taken care of
 
 } else if($_GET['act'] == "login"){
//check the user details
$check = mysql_query("SELECT * FROM `users` WHERE `username` = '{$_POST['username']}' AND `password` = 'md5($_POST['password'])'");
if(mysql_num_rowS($check) > 0){
//The user had the correct login details
echo("You have been logged in.");
$_SESSION['loggedin'] = "true";
$_SESSION['username'] = $_POST['username'];
} else {
//There was an error
echo("The username/password was not found.");
}

?>
subzero Super moderator Fellow · 3,954 posts #2

With error messages you use die("Sorry Your didnt use the password or username");

it kills other but in side die(" here only thing will load ");

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close