Welcome Guest, Not a member yet? Register   Sign In
URI-Safe Encrypt Library Extension
#1

[eluser]TheFuzzy0ne[/eluser]
I extended the CI_Encrypt class, as I wanted to have the ability to send an encrypted string over the URI, without triggering the infamous "The URI you submitted has disallowed characters." message. I use it for my "Forgot Password" module on my Web site. I encrypt the users Email address, and the last 16 characters of their MD5 hashed password, and this is then decoded and used to validate the user.

I hope someone might find it useful.

Code:
<?php
/**
* This class extends the core Encrypt class, and allows you
* to use encrypted strings in your URLs.
*/
class MY_Encrypt extends CI_Encrypt
{
    /**
     * Encodes a string.
     *
     * @param string $string The string to encrypt.
     * @param string $key[optional] The key to encrypt with.
     * @param bool $url_safe[optional] Specifies whether or not the
     *                returned string should be url-safe.
     * @return string
     */
    function encode($string, $key="", $url_safe=TRUE)
    {
        $ret = parent::encode($string, $key);
        
        if ($url_safe)
        {
            $ret = strtr(
                    $ret,
                    array(
                        '+' => '.',
                        '=' => '-',
                        '/' => '~'
                    )
                );
        }
        
        return $ret;
    }
    
    /**
     * Decodes the given string.
     *
     * @access public
     * @param string $string The encrypted string to decrypt.
     * @param string $key[optional] The key to use for decryption.
     * @return string
     */
    function decode($string, $key="")
    {
        $string = strtr(
                $string,
                array(
                    '.' => '+',
                    '-' => '=',
                    '~' => '/'
                )
            );
            
        return parent::decode($string, $key);
    }
}

// End of file: MY_Encrypt.php
// Location: ./system/application/helpers/MY_Encrypt.php


Messages In This Thread
URI-Safe Encrypt Library Extension - by El Forum - 03-22-2009, 05:56 PM
URI-Safe Encrypt Library Extension - by El Forum - 03-23-2009, 04:32 AM
URI-Safe Encrypt Library Extension - by El Forum - 03-23-2009, 05:19 AM
URI-Safe Encrypt Library Extension - by El Forum - 08-19-2009, 09:12 PM
URI-Safe Encrypt Library Extension - by El Forum - 04-13-2010, 11:51 AM
URI-Safe Encrypt Library Extension - by El Forum - 04-15-2010, 06:34 PM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 08:32 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 09:10 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 09:12 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 09:55 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 10:28 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 10:40 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 11:06 AM
URI-Safe Encrypt Library Extension - by El Forum - 05-13-2010, 11:41 AM
URI-Safe Encrypt Library Extension - by El Forum - 07-09-2010, 02:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB