We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38357
    • 178 Posts
    Hello again,
    Not being really familiar with all aspects of Modx and how they integrate, and also having rather limited php skils I sometimes run into trouble with what i want to do :-(
    I need to encrypt the username when a user logs on and pass it to a remote domain where it will be decrypted and used to provide the user with access to offsite information. The user will be logged on to my site and be able to access and use the pages from the remote server. This is to try and avoid multiple logons. Only the username needs to be sent.

    If I used code similar to:
    $key = 'key used to (en/de)crypt';
    
    $string = ' string to be encrypted ';
    
    encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));


    Where would I place it - in the Login template?
    How would I be best to post the encryption key and data to the other site?
    Is there a better solution ?

    Thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You would probably be best off using a plugin for this. When the visitor is successfully logged in to the MODx site, then the username gets encrypted and possibly passed in a cookie assigned to the other domain.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 38357
        • 178 Posts
        Thanks for the response Susan. now I'm on totally new ground. Are there plugins available to do this or would one have to be written?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You would have to write a custom plugin, I'm sure. There would be too many variables here; how to encrypt the username and what to do with it after it's encrypted.

          I would be inclined to save it to the user's SESSION, then have a link with the encrypted username added to the URL when going to the other site. Or, as I mentioned before, save it to a cookie assigned to the other domain.

          Another option would be to create the encrypted username on creating the user (again a plugin, just a different event), save it to the user_settings table, then use a snippet to fetch it when needed.

          It depends on when you want this available; will the user always go to the other site as soon as he's logged in, or will he have links available to go to the other site at his convenience?
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 38357
            • 178 Posts
            Thanks again Susan,
            This seems to be a bit beyond my skills :-(
            The user will have menu links available to go to the other site at his convenience.
              • 3749
              • 24,544 Posts
              Do you know how the other site wants to receive the information? It might be a relatively simple plugin or Login postHook. If the other site has an API, they should have some example code somewhere.



              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 38357
                • 178 Posts
                Thanks for the help Bob. I'll have to find out - not sure at the moment. I'll come back when I find out. It might take me 24 hours.