Jump to content

AParson

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Posts posted by AParson

  1. Encryption is what you're after.

    Aha! I think you may be right. I only have to ask the customer, if the data will have to be decripted at some point. Either way, anything that can give the customer the expected result will do (either hash/encryption function).

     

    What kind of input are you expecting? do the strings have to be the same length like with md5 and sha1 or can it be just be something where A = Z and B = Y (in it's most simple form) making the string length depending on the input.

    Basically it's a (15-character maximum) password, and a UNIX timestamp. The encrypted (or hashed) output should be in a "hex triplet" (web color) format... something like "000000" or "fa37d1". Those are gonna be recorded in two separate, extra fields.

     

    I asked the customer why does it have to be that way... he then went red, sighed and asked "Can you do it or not?". He's a very old-fashioned and stubborn person, I have to say.

     

    I missed the part about the "difficult to decode."  In that case, add a salt to your string, serialize it, THEN use bin2hex.. easy enough.

    The salt is what keeps it all different.  It's pretty much a password.

    Say you have the string "bubble" and you want to encode it..

    That might help, depending on whether or not the customer will need that data decrypted at some point.

     

    If not, in the end I might just use "md5()" and get the 6 first characters, which should give him what he wants, but I have a felling it's not gonna be that simple...

     

    Thanks everyone for your inputs, I'll let you know how it panned out.

  2. Loading a MD5 salt hasched password from my MYSQL database.

    You'll get to fill in one field: Password. If it validates with the MYSQL password it'll show the hidden content; if not it'll just give a "not correct error".

     

    I didn't test it to see if it works, but here goes (just replace table names and other stuff with the ones you have).

     

    <?php
    
    //Allowing session vars
    session_start();
    
    //Connecting to a MySQL DB
    $connection = @ mysql_connect('host', 'user', 'pass') or die('Error: cannot connect database.');
    mysql_select_db('dbname', $connection);
    
    //Retrieving the value typed on a form textbox (I'm assuming there was a form on the previous page, with a "password" field)
    $typed_password = '';
    if (isset($_POST['txtPassword'])) $typed_password = trim($_POST['txtPassword']);
    
    //Hash the data retrieved from the form field, to compare with the hashed value in the DB table field.
    //Note that I didn't salt this one, that's gonna be up to you, if the one recorded on the table is salted.
    $hashed_password = hash('md5', $typed_password);
    
    //Querying for the user name, comparing the typed password with the one on the BD
    $sql = 'SELECT theTable.theName FROM theTable WHERE (theTable.thePassword="' . $hashed_password . '");';
    $success = @ mysql_query($sql) or die('Error retrieving data.');
    
    if (mysql_num_rows($success) > 0) {
    
    //Success! Get the user name, and...
    $userdata = mysql_fetch_array($success);
    
    //... create all necessary session vars.
    //You can use this one to check every page if you are still logged in
    $_SESSION['loggedin'] = 'yes';
    //And this one, just for display purposes
    $_SESSION['username'] = $userdata['name'];
    //Just for display
    echo 'Welcome back, ' . $_SESSION['username'] . '.';
    
    }
    
    else {
    
            //Password didn't match.
    echo 'Wrong password.';
    
    }
    
    //Closing query and connection to DB
    mysql_free_result($success);
    mysql_close($connection);
    
    ?>

     

  3. I might be wrong, but #anchor_name only works if you use "filename.extension#anchor_name" (like in "page.html#myanchorname").

     

    Sorry, I think I just said rubbish.

     

    I checked your code, and the line where #respond is supposed to anchor might need to be changed.

     

    You have "<a name="add_response"></a>" in your code, so:

     

    1) Change the value "add_response" for "respond"

    2) Move the whole "<a name="respond"></a>" inside "<h3 id="respond">Leave a Reply</h3>"

    3) Eliminate "id="respond"" from <h3 id="respond">

     

    The result should look like this:

     

    <h3><a name="respond">Leave a Reply</a></h3>

     

    Hope it helps.

  4. Hi,

     

    I am working on a project, and my customer is demanding some sort of "non-standard" hashing to encode field values on a database. This customer wants something exclusive, difficult to be decoded, and would accept no argument proving that the existing hash algorithms are good enough for the job.

     

    What makes it even more challenging for me is that I don't have much experience in PHP.

     

    The output should be something similar to a hex triplet (web color), so... this basically means I cannot use MD5, SHA, etc.

     

    This also means that PHP hash() function is useless in this case, unless there is a hash algorithm I don't know about, and that gives me the output I need.

     

    What I need is something like:

    $output = functionthatdoesntexist("string to be encoded");

     

    The "$output" var should contain something like: 19f7b4 (this is just a random value I am using to illustrate the format required for the output.)

     

    Now here are my questions:

     

    1) Is there a PHP function that encodes a string/number, and gives me back a "hex triplet"?

    2) If such function doesn't exist, is there a way to create one from scratch? How should I start?

     

    I just can't figure out how to solve this problem, so any help is appreciated.

     

     

    Thanks in advance,

     

     

    AP

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.