PHP forms and security

Discussion in 'OT Technology' started by Leb_CRX, Jun 21, 2005.

  1. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    I've done an order form for a client that once filled out, sends it to her email, works fine as there was no sensitive data on it...now she wants to add some stuff there such as CC information, not checking whether or not it's valid, SHE will take care of that, just sending...now the page resides on a secure server, and I need to get opinions on what is the best way to handle this data processing?

    I've never had to deal with handling this type of data...but the most logical way of doing it I can think of is once a form is filled out, it sends her an email notifying her...without any data, she goes to a specific page only she has access to (u&p), and views the form elements that way...form elements are stored in a mysql DB along with her u&p

    any feedback? :dunno:
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    I've done something very similair to this in the past. I used encryption. My suggestion would be to encrypt the data before you send it out. Then when it appears in her e-mail it is encrypted. If she wants to view the CC#, then make an reports page that will decrypt the data (Which I hope it is encrypted if you are inserting into the DB) and display it.

    That's the only way I can think of doing it. If she wants the CC to be displayed in her e-mail address... well, you'll just have to explain to her the huge security risk in that.
     
  3. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    well I refuse to have the CC info display in her email...period, especially if she goes around saying this data is secure, and misleading people, that's not right morally for me.

    the data does not have to come in her email...ideally she wants it that way I think, so I like that encrypting/sending in email idea, I am not sure how much of the 'going to another page to decrypt it' idea she'll like, but I'll see what I can do

    BTW...is there a specific algorithm/way to encrypt/decrypt the data or any resources I can use or should I just go wild mathematically?
     
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    That is a good point. No displaying the CC period is a LOT better than displaying the CC encrypted.

    But yeah, she'll want the CC in her e-mail box, customers are like that. :hsugh: Perhaps when sending her the report, in the CC# area put a link to a password protected page that will have the report of the client. But if she still insists, I'd end up doing an encryption thing. I had to do that. :o

    PHP has built in functions that handle can handle encryption rather well (I'm not talking about Hashing). I did some research on it a while back but I do not have the resources at my finger tips. Hit up the documentation. I recall there were a lot of examples of encryption algorithms and implimentation in their documentation.
     
  5. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    sweet, thanks King

    you've pointed me in the right direction :x:
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    If it helps any, here is encryption that a friend of mine uses for his ISP firm.

    The class
    PHP:
    <?php

    class phpFreaksCrypto
    {
        var 
    $td;
        
        function 
    phpFreaksCrypto($key 'MyRandomStringThatWillAlwaysBeTheSame'$iv false$algorithm 'tripledes'$mode 'ecb')
        {
            if(
    extension_loaded('mcrypt') === FALSE)
            {
                
    $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' '';
                
    dl($prefix 'mcrypt.' PHP_SHLIB_SUFFIX) or die('The crypt module could not be loaded.');
            }
            
            if(
    $mode != 'ecb' && $iv === false)
            {
                die(
    'In order to use encryption modes other than ecb, you must specify a unique and consistent initialization vector.');
            }
            
            
    $this->td mcrypt_module_open($algorithm''$mode'');
            
    $random_seed strstr(PHP_OS"WIN") ? MCRYPT_RAND MCRYPT_DEV_RANDOM;
            
            
    $iv = ($iv === false) ? mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), $random_seed) : substr($iv0mcrypt_enc_get_iv_size($this->td));
            
            
    $expected_key_size mcrypt_enc_get_key_size($this->td);
            
            
    $key substr(md5($key), 0$expected_key_size);
            
    mcrypt_generic_init($this->td$key$iv);
        }
        
        function 
    encrypt($plain_string)
        {
            return 
    base64_encode(mcrypt_generic($this->td$plain_string));
        }
        
        function 
    decrypt($encrypted_string)
        {
            return 
    trim(mdecrypt_generic($this->tdbase64_decode($encrypted_string)));
        }
        
        function 
    __destruct()
        {
            
    mcrypt_generic_deinit($this->td);
            
    mcrypt_module_close($this->td);
        }
    }
    ?>
    Implementation
    PHP:
    require_once('encrypt.class.php');

    $crypto = new phpFreaksCrypto();
    $the_string_to_be_encrypted 'blah.blah.blah';

    $the_string_that_is_encrypted $crypto->encrypt($the_string_to_be_encrypted);
    $the_encrypted_string_decrypted $crypto->decrypt($the_string_that_is_encrypted);
    $crypto->__destruct();

    echo 
    'Original: ' $the_string_to_be_encrypted;
    echo 
    'Encrypted: ' $the_string_that_is_encrypted;
    echo 
    'Decrypted: ' $the_encrypted_string_decrypted
     
  7. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    :bowdown:

    perfect

    now I gotta see what the client says....ahh aint that the funnest part :wtf:
     
  8. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    Just tell her that the security of the credit card #s are only as secured as her e-mail, which includes physical access, such as no passwords to her computer. Therefore it is best to have a secured server store the #s.
     

Share This Page