Incorrect password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mankolele
    New Member
    • Sep 2006
    • 63

    Incorrect password

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Simple Database Connection</title>
    </head>
    <body bgcolor="white" >

    <?php
    $connection = mysql_connect(" localhost", "root", "phpmysql") ;
    $select_db = mysql_select_db ("procdumy", $connection);
    $query = mysql_query ("SELECT username, password FROM users", $connection);


    if(isset( $_COOKIE['ID_my_site']))

    //if there is, it logs you in and directes you to the members page
    {
    $name = $_COOKIE['ID_my_site'];
    $pass = $_COOKIE['Key_my_site'];
    $check = mysql_query("SE LECT password FROM users WHERE username = '$username'")or die(mysql_error ());
    //$check = mysql_query("SE LECT cust_username,c ust_pswrd FROM customer WHERE cust_username = '$cust_username '")or die(mysql_error ());
    while($info = mysql_fetch_arr ay( $check ))
    {
    if ($pass != $info['password'])
    {
    }
    //else
    //{
    //header("Locatio n: welcome.php");

    //}
    }
    }

    //if the login form is submitted
    if (isset( $_POST['submit'])) { // if form has been submitted

    // makes sure they filled it in
    if(! $_POST['name'] | ! $_POST['pass']) {
    die('You did not fill in a required field.<a href=login.php> back</a>');
    }
    // checks it against the database

    if (!get_magic_quo tes_gpc()) {
    $_POST['email'] = ( $_POST['email']);
    $_POST['email'] = addslashes( $_POST['email']);
    }
    $check = mysql_query("SE LECT password FROM users WHERE username = '". $_POST['name']."'")or die(mysql_error ());

    //Gives error if user dosen't exist
    $check2 = mysql_num_rows( $check);
    if ($check2 == 0) {
    die('That user does not exist in our database.

    <a href=reg.php>Cl ick Here to Register</a>');
    }
    while($info = mysql_fetch_arr ay( $check ))
    {
    $_POST['pass'] = stripslashes( $_POST['pass']);
    $info['password'] = stripslashes($i nfo['passwordd']);
    $_POST['pass'] = md5( $_POST['pass']);

    ///*
    //gives error if the password is wrong
    //if ( $_POST['pass'] != $info['password']) {
    //if (md5( $_POST['pass'] ,$info['cust_pswrd'] ==$info['cust_pswrd'])){
    if ( $_POST['pass']!= $info['cust_pswrd']) {
    echo $_POST['pass']."<br>\n";
    echo $info['password']."<br>\n";
    die('Incorrect password, please try again.<a href=login.php> Click Here </a>');
    }
    else
    {
    //*/
    // if login is ok then we add a cookie
    $_POST['name'] = stripslashes( $_POST['name']);
    $hour = time() + 3600;
    //setcookie(ID_my _site, $_POST['name'], $hour);
    //setcookie(Key_m y_site, $_POST['pass'], $hour);

    //then redirect them to the members area
    header("Locatio n: welcome.php");
    }
    }
    }
    else
    {

    // if they are not logged in
    ?>
    <TR>
    <TD><IMG height=115 src="resources/visitorsBanner. png" width="100%"></TD>
    </TR>
    <form action="<?php echo $_SERVER['../test/PHP_SELF']; ?>" method="post">
    <table border="0">
    <tr><td colspan=2><h1>L ogin</h1></td></tr>
    <tr><td>Usernam e:</td><td>
    <input type="text" name="name" maxlength="40">
    </td></tr>
    <tr><td>Passwor d:</td><td>
    <input type="password" name="pass" maxlength="50">
    </td></tr>
    <tr>
    <td colspan="2" align="right"> <input type="submit" name="submit" value="Login">
    <input type="Reset" value="Clear Form" ></td>
    </tr>
    </table>
    </form>
    <?php
    }

    ?>

    </body>
    </html>

    I am trying to log on with this code everything else works but the password say its incorrect.on the database it it 32bits long I cant see where my proble is.
    Any bright idea for me on what s wrong??
    tried all the commented codes.

    Thanx


    I am trying to log on with this code everything else works but the password say its incorrect.on the database it it 32bits long I cant see where my proble is.
    Any bright idea for me on what s wrong??
    tried all the commented codes.

    Thanx
    Last edited by Niheel; Sep 6 '06, 12:55 AM.
  • mankolele
    New Member
    • Sep 2006
    • 63

    #2
    Cannot modify header information

    Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\h tdocs\php\dumy\ login.php:9) in C:\Program Files\Apache Group\Apache2\h tdocs\php\dumy\ login.php on line 86

    Oh the password I did see the mistake eventually after a week looking at the code.now it gives me the heasder location error above.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      I merged your threads because the second one did not make sense if you hadn't read the first one and I have moved them to the PHP forum since that's what they are about.

      On to the problem

      In PHP you can only call the header() function before you output and of the actual page because the headers have to be sent first. As soon as you output any other data either using print, echo or just having it in the file (like your DOCTYPE) then PHP sends all the current headers and your chance to modifiy them has passed.

      You need to alter the page so that it sets the headers before it outputs any of the page.

      Comment

      Working...