Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Results 1 to 7 of 7

Thread: md5 problem in login

  1. #1
    amber.long83 is offline Junior Member
    Join Date
    Mar 2009
    Posts
    11

    Default md5 problem in login

    Problem in my login script. In my script password in md5 hash in the registration. registration is successful and the password is in md5 form in the database table.
    But whenever I try to login is not == with md5 password in the database.

    Code

    <?php
    include 'dbconnect.php';

    if(!$_POST['submit'])
    {
    ?>

    <html>
    ...
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p>Username&nbsp;:</br>
    <input type="text" name="username" maxlength="20">
    </p>
    <p>Password&nbsp;:</br>
    <input type="password" name="password" maxlength="20">
    </p>
    <p>
    <input type="submit" name="submit" value="Submit">
    </p>
    </form>
    ...
    </html>
    <?php
    }
    else
    {
    $username = cleanString($_POST['username']);
    $password = cleanString($_POST['password']);

    if($username && $password)
    {
    $password = md5($password);
    $sql="SELECT id,username FROM `users` WHERE `username`='$username' AND `password`='$password'";
    $query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) > 0)
    {
    $row = mysql_fetch_assoc($query);
    $_SESSION['id'] = $row['id'];
    $_SESSION['username'] = $row['username'];


    echo "<script type=\"text/javascript\">window.location=\"members_area.php\"</script>";
    }
    else
    {
    echo "<script type=\"text/javascript\">
    alert(\"Your username or password is incorrect\");
    window.location=\"index.php\"</script>";
    }
    }
    else
    {
    echo "<script type=\"text/javascript\">
    alert(\"You need to input your username and password\");
    window.location=\"index.php\"</script>";
    }
    }
    ?>

    Anyone can please help me for correct my problem

    Thanks in Advnace

  2. #2
    RussellReal is offline Junior Member
    Join Date
    Dec 2009
    Posts
    2

    Default

    $password = cleanString($_POST['password']);

    there is NO need to do this.. you're going to MD5 it anyway, that is probably where it is messing up

  3. #3
    silverf0x's Avatar
    silverf0x is offline Member
    Join Date
    Jul 2010
    Posts
    53

    Default

    maybe it's better you use stripslashes than cleanstring the password

  4. #4
    phpSiteMinder is offline Junior Member
    Join Date
    May 2010
    Posts
    2

    Default

    What does the function cleanString do? Its probably altering the posted value, so that its different to the md5 that is stored in the database.

    Also check that the md5 in the database is the right md5 for the password. There may have been a problem when registering, if the md5 wasn't generated using the cleanString function.

    Also I dislike the use of :
    $sql="SELECT id,username FROM `users` WHERE `username`='$username' AND `password`='$password'";
    and relying on counting the rows to indicate whether the user can login. If your cleanString functions is not able to remove all sql injection hacks, then someone may be able to gain access to your system.

    A better way is to retrieve the password from the database for the username, and compare the passwords in php to determine if the user can log in. Even with no protection from sql injection, this approach will still prevent unathorised access.

  5. #5
    tinaCEO is offline Junior Member
    Join Date
    Jul 2010
    Posts
    8

    Default

    Use debugging software to find out error. Rather than putting your own head on it. I recommend HTTP Debugger that is best to use.

  6. #6
    norbertwarne is offline Junior Member
    Join Date
    Oct 2010
    Posts
    17

    Default

    Use rectifying software to detect out error. Rather than investing your own head on it. I advocate HTTP Debugger that is better to use.

  7. #7
    damienb is offline Junior Member
    Join Date
    Oct 2010
    Posts
    10

    Default

    If I were you I would have used stripslashes() function instead of cleanString().
    Last edited by damienb; 11-18-2010 at 10:18 AM.

Thread Information

Users Browsing this Thread

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

Bookmarks

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124