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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts

    login username issue

    If a username registers, their username's first letter is automatically capitalized and sent to the database. If a user decides to capitalize a second letter in the middle of their username (Ex: McLoven), unless the username is typed with that capitalized letter, I get an error that says "Incorrect Password!". The password is set as an MD5 encryption.

    Any suggestions on what to do to fix this problem?

    MySql version: 5.0.91

    Here's my Login.php

    PHP Code:
    <?php
    $username 
    ucfirst($_POST['username']);
    $password $_POST['password'];


    include(
    'inc/connect.php');
    if (
    $username&&$password)
    {

    $query mysql_query("SELECT * FROM users WHERE username='$username'");

    $numrows mysql_num_rows($query);

    if (
    $numrows!=0)
    {

     while (
    $row mysql_fetch_assoc($query))
     {
           
    $dbusername $row['username'];
           
    $dbpassword $row['password'];
           
    $userid $row['id'];



    // $_SESSION['username'] = $username;
    // $_SESSION['userid'] = $userid;
     
    }

     
    // check to see if they match
     
    if ($username==$dbusername&&md5($password)==$dbpassword)
    {
      
    //echo "You're In! <a href='member.php'>Click</a> here to enter the member page.";
      
    session_start();
      
    $_SESSION['username']=$username;
      
    $_SESSION['views'] = 0;
      
    header('Location:http://www.daobux.com/member.php');
    }
    else
        echo 
    "Incorrect Password!";

    }
    else
        die(
    "That user doesn't exist!");


    }
    else
        die(
    "Please fill out all fields!");


    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    You let them enter it any way they want (any combination of caps and small),
    and then you make the whole thing lowercase before you save it.

    $username = strtolower($_POST['username']);

    If it's important to let them specify caps and small, then save it BOTH ways,
    as two usernames. Always use the lowercase for login, but show them the
    other one if they need to see it with mixed small and caps.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Incorect password error can only be true if your query returns at least 1 result. Unless you collate your query, declare a binary derived type, or declare it as case sensitive, mysql will search insensitively.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    Let them enter their user name any way they want. Don't try to force anything to something they didn't type. The prompt should let them know their user name is case sensitive.

    If you *must* play with their entry then just force everything to all lowercase but keep that info to yourself. They don't need to know that.
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com


  •  

    Posting Permissions

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