Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    error with login auth

    I have the next code:

    PHP Code:
    $link mysql_connect('localhost''myusername''mypass' );
    mysql_select_db('mydb') or die("check your info."); 

    $_POST['username'] = $username;
    $_POST['password'] = $password;
    $password md5($password);

    $consult"SELECT * FROM users WHERE password='$password' AND username='$username'";

    $resultmysql_query($consult,$link);
    echo 
    mysql_error();


    // Check auth
    if($username=$row['username'] && $password=$row['password']){
     echo 
    "all success";
    }else{
     echo 
    "login failed";

    For some reasons my code don't work! Can somebody fix this? my password are encrypted(md5). Regards

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    First of all...please correct the following statements

    from
    PHP Code:
    $_POST['username'] = $username;
    $_POST['password'] = $password
    to
    PHP Code:
    $username $_POST['username']; 
    $password $_POST['password'] ; 
    Second...if you haven't stored user's passwords in the database encrypted in md5...it won't work.

    So...I would advise to you get the script working without using md5 first...

    once you have...go back and implement md5 in your script.

    Good luck


  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    implementation for md5 is made. check the footer of my message

    I made the changes that you say me and the problem is same.

    Regards
    Last edited by urgido; 11-03-2006 at 08:12 PM.

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Use mysql_fetch_assoc.

    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I put the following code:

    PHP Code:
    while ($fila mysql_fetch_assoc($result)) {
       
    //nothing

    How I can compare the values to know if there are correct. I you remember that the username and password must coincide to be able to go to cp.php of another way errorcp.php
    ?

    Regards

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You could use mysql_num_rows():
    PHP Code:
    $link mysql_connect('localhost''myusername''mypass' );
    mysql_select_db('mydb') or die("check your info."); 

    $_POST['username'] = $username;
    $_POST['password'] = $password;
    $password md5($password);

    $consult"SELECT * FROM users WHERE password='$password' AND username='$username'";

    $resultmysql_query($consult,$link);

    if(
    mysql_num_rows($result) > 0)
    {
        
    // good login...do whatever
    }
    else
    {
        
    // login failed.

    Ref:
    http://us2.php.net/mysql_num_rows

  • #7
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Brandoe85 THANKKKKKKKKKKKKKKKKKKKKKKKKKK YOU.

    BEST REGARDS!

  • #8
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Woops, I didn't put in the other fixes for the tranposed variable names but you get the idea. Good luck


  •  

    Posting Permissions

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