We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36702
    • 76 Posts
    WebLoginPE lets users log in with their username + password. I want to allow them to log in with either their username + password or their email address + password. Has anyone else done this? Any tips on how this might be achieved?
      • 3749
      • 24,544 Posts
      It seems like it would be easy to change the caption to "Username or Email" and then modify the code to look the user up by email if there was an @ sign in the response.
        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
        • 36702
        • 76 Posts
        Thanks for the reply BobRay. There’s a slight complication in that some people have used their email address as their username too (so some usernames have @ in them). I realise I probably need to modify the Login function in webloginpe.class.php but the question is how? That function does stuff I don’t really understand.

        Maybe the easiest way is to add some code near the top of the function:

        • Check if the value entered is an existing username
        • If yes, continue as normal
        • If not, see if it’s an existing email address - if it is, look up the corresponding username and use that for the rest of the function.

        Does that make any sense?
          • 3749
          • 24,544 Posts
          Quote from: twz at Jun 08, 2010, 02:21 AM

          Thanks for the reply BobRay. There’s a slight complication in that some people have used their email address as their username too (so some usernames have @ in them). I realise I probably need to modify the Login function in webloginpe.class.php but the question is how? That function does stuff I don’t really understand.

          Maybe the easiest way is to add some code near the top of the function:

          • Check if the value entered is an existing username
          • If yes, continue as normal
          • If not, see if it’s an existing email address - if it is, look up the corresponding username and use that for the rest of the function.

          Does that make any sense?

          It sounds like a really good solution to me.

          BTW, you might want to duplicate and rename the snippet (e.g. MyWeblginPE) so that it can’t be overwritten during an upgrade.
            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
            • 36702
            • 76 Posts
            That’s probably what I’ll end up doing then (when I can get to it). I was hoping it could be done without modifying the source code, but I guess not.