i want taht my password fiweld should ?

Discussion in 'PHP' started by hulkrana, Jul 1, 2007.

  1. #1
    i want that my password field should contain both capital and small letters?please suggest me wat condition as i need to apply?
    thanks
     
    hulkrana, Jul 1, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    
    $a="ssssssdss";
    echo ( preg_match("/[a-z]/",$a) && preg_match("/[A-Z]/",$a) ) ? "it's good" : "it's bad";
    
    PHP:
     
    ansi, Jul 2, 2007 IP
  3. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #3
    md5 the password in the database. Then when they try to log in, verify that the query returns a result.

    "SELECT 1 WHERE user=" . $user . " AND password = " . md5($password);
     
    KalvinB, Jul 2, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    that has nothing to do with checking for both ucase and lcase characters within the user input.
     
    ansi, Jul 2, 2007 IP
  5. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Read the OP wrong. I thought he was asking about checking the password. MySQL isn't case sensitive by default so md5 is the easy way to make passwords case sensitive.

    If you verify case changes in the input but then do "SELECT 1 WHERE user=$user and password=$password" you didn't accomplish anything.

    You could also use Javascript to check the password. You just compare the original string to the all uppercase version of the string and the all lower case version of the string. If either of those match then the password is either all lowercase or all uppercase and you can simply alert the user before wasting time processing their input on the server side.
     
    KalvinB, Jul 2, 2007 IP
  6. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #6
    so using md5, show me how you intend to check for both upper and lowercase characters in the input before it is hashed.
     
    ansi, Jul 2, 2007 IP
  7. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #7
    reread my post. Then try responding again.
     
    KalvinB, Jul 2, 2007 IP
  8. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #8
    heh, you changed the post 3 minutes after i responded....
    either way, a pattern match is the best way to go. be it in php or javascript.

    
    <?php
        // $a = input
    
        if ( preg_match("/[a-z]/",$a) && preg_match("/[A-Z]/",$a) )
        {
            // it's good
        }
        else
        {
            // it's bad
        }
    
    PHP:
    javascript:

    // a = input

    if (a.match(/[a-z]/) && a.match(/[A-Z]/)) {
    // it's good
    } else {
    // it's bad
    }
     
    ansi, Jul 2, 2007 IP