Newbie question

Discussion in 'PHP' started by jeffjustice, Jul 6, 2008.

  1. #1
    Hello!
    I am new to PhP and I need to make a simple login page. I searched the web for some tutorials and found this one: codervods.com/VideoPage.aspx?ID=915&&category=All
    I want to know if there is any way to hide the password for some users who have acces to the database.
     
    jeffjustice, Jul 6, 2008 IP
  2. whirlybird20

    whirlybird20 Guest

    Messages:
    462
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you talking about a database that stores the users usernames and passwords? Anything with in the <? code here ?> or the <?php code here ?> tags will not show up in the source code.
     
    whirlybird20, Jul 7, 2008 IP
  3. wowla_123

    wowla_123 Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to encrypt passwords in the database, you can use md5() function.

    For example, when saving a password (for example apple), you will first encrypt it and then save in the database:

    <?php
    $str = md5("apple");
    
    // Save $str in the database
    
    ?>
    PHP:
    When a user tries to login and you need to check if the password is valid, do the following:

    <?php
    $userpass = $_POST['mypassword'];
    
    // $userpass contains the password got by the user
    
    // Now get the encrypted password saved in the database. Suppose, it is stored in variable $dbpass
    
    if (md5($userpass) == $dbpass)
        {
        echo "password is correct";
        }
    else
        {
        echo "password is incorrect"; 
        }
    ?>
    PHP:
     
    wowla_123, Jul 7, 2008 IP
  4. jeffjustice

    jeffjustice Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks, wowla_123. It really helped.
     
    jeffjustice, Jul 7, 2008 IP