+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    Junior Member PiN2 is on a distinguished road
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default 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. #2
    Super Moderator subzero is an unknown quantity at this point subzero's Avatar
    Join Date
    Mar 2006
    Location
    Your Screen.
    Posts
    2,828
    Thanks
    76
    Thanked 75 Times in 39 Posts
    Blog Entries
    2
    Rep Power
    0

    Default

    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 ");




    Super Cheap hosting:
    Read Tearms&Conditions here:
    FAQ:
    Support forum:


    WapMasterz.Net is back with new forum style!!
    Click this image to goto wapmasterz site!



  3. #3
    Senior Member makvanpor2000 is on a distinguished road makvanpor2000's Avatar
    Join Date
    Apr 2009
    Location
    DEATH VALLEY
    Posts
    254
    Thanks
    22
    Thanked 2 Times in 2 Posts
    Rep Power
    2

    Default Thanks

    It really nice script
    thans but i can i encrypt the pssword
    THE PEOPLE`S CHAT

    AM A VERY LAZY CODER, I KNOW ALREADY...................

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. mobilezonez v2
    By ozziemale31 in forum Scripts Forum
    Replies: 70
    Last Post: 13-03-10, 11:13
  2. [web] 65 Most Needed Php Scripts
    By jayasanka in forum Scripts Forum
    Replies: 18
    Last Post: 14-01-10, 12:54
  3. Pro Chat Rooms V3.0.2 Php Nulled
    By jayasanka in forum Scripts Forum
    Replies: 6
    Last Post: 03-12-08, 22:14
  4. Learn Php In 10 Minutes
    By wapkralj in forum Tutorials
    Replies: 8
    Last Post: 16-08-06, 22:43
  5. Introduction to PHP
    By AcidBurn in forum Tutorials
    Replies: 7
    Last Post: 26-06-06, 11:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO