Grow your CSS skills. Land your dream job.

[Solved] User Authentication (without db)

  • # July 13, 2010 at 1:03 pm

    Hey guys, I setup a page to input information into a database, but to do so, the page is password protected, and each user has an authentication password which goes through a salted hash. What I wanted to do is keep the variables in php (because I don’t know how to do it with a database) with something like this..

    Code:
    $user_authentication = array(
    ‘users’ => array(
    ‘dyllon’ => ‘foo’,
    ‘robb’ => ‘bar’
    )
    );

    So if the user types in foo to authenticate, it returns that dyllon has inserted information into the table, and if bar is used, it returns that robb did.

    Is there a way I can search the array for the specified value, as well as return it’s key?

    # July 13, 2010 at 1:28 pm

    Nevermind, I got it.

    This is the final code I came up with:

    Code:
    $authentication = $_POST[’authentication’];
    $user_authentication = array(
    ‘users’ => array(
    ‘dyllon’ => ‘foo’,
    ‘robb’ => ‘bar’
    )
    );

    foreach($user_authentication as $key){
    foreach($key as $key => $val){
    if($authentication == $val){
    echo $key;
    }
    }
    }

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".