NYCPHP Meetup

NYPHP.org

[nycphp-talk] One Login for multiple sites

Daniel Convissor danielc at analysisandsolutions.com
Tue Jun 21 12:06:02 EDT 2005


On Mon, Jun 20, 2005 at 10:37:27AM -0400, John Nunez wrote:
> We have a database where we store articles for a web site.  We have  
> begun a project to allow another site's users to access our articles.  
> I thought that best and easiest method would be to have the user  
> click on a link to our database site and that link passes and  
> encrypted string that contains the user's information.

THE easiset solution for you is to grant the remote site read privileges 
on the database and let them sort out how to authenticate the users and 
display the information.

Anyway, if you do want to pass encrypted information in the URI, here's 
how I do it:

/**
 * encrypt a string using mcrypt, base64 and urlencode
 *
 * @link http://php.net/ref.mcrypt
 * @link http://ftp.emini.dk/pub/php/win32/mcrypt/
 * @link http://mcrypt.sourceforge.net/
 */
function encrypt_string($string) {
    return urlencode(
        base64_encode(
            mcrypt_encrypt(
                MCRYPT_BLOWFISH,
                'Your Passphrase Goes Here',
                $string,
                MCRYPT_MODE_ECB,
                mcrypt_create_iv(
                    mcrypt_get_iv_size(
                        MCRYPT_BLOWFISH,
                        MCRYPT_MODE_ECB
                    ),
                    MCRYPT_RAND
                )
            )
        )
    );
}

/**
 * decrypt a string using urldecode, base64 and mcrypt
 *
 * @link http://php.net/ref.mcrypt
 * @link http://ftp.emini.dk/pub/php/win32/mcrypt/
 * @link http://mcrypt.sourceforge.net/
 */
function decrypt_string($string) {
    return rtrim(
        mcrypt_decrypt(
            MCRYPT_BLOWFISH,
            'Your Passphrase Goes Here',
            base64_decode(urldecode($string)),
            MCRYPT_MODE_ECB,
            mcrypt_create_iv(
                mcrypt_get_iv_size(
                    MCRYPT_BLOWFISH,
                    MCRYPT_MODE_ECB
                ),
                MCRYPT_RAND
            )
        )
    );
}

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list