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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

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


    First we will need to create a user's table
    MYSQL Query:
    Code:
    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 Code:
    <?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 Code:
    <?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 Code:
    <?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.");
    }

    ?>

    #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...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      Thanks

      It really nice script
      thans but i can i encrypt the pssword
      http://myfacepals.com
      MYFACEPALS SOCIAL NETWORKsigpic

      Comment

      Working...
      X