Email Address as Username

Discussion in 'Customization & add-ons' started by bigstrategies, Mar 20, 2008.

  1. bigstrategies

    bigstrategies New Member

    Joined:
    Dec 3, 2007
    Messages:
    1
    Hi,
    Is it possible to have the users email address as the username when the signup instead of them choosing their own?

    Thanks
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    If you select (in global settings) for Amember to automatically generate a user id it will use the first part of the user email (left side of the @ symbol) as the auto generated name.

    so username@email.com -> username
  3. nomaddesign

    nomaddesign Member

    Joined:
    Aug 25, 2005
    Messages:
    67
    It would be very helpful to use the email address AS the username. This not only cuts down the number of fields required on the signup form... but also makes it easier for the customer to remember his username.


    Consider this my vote for allowing use of full email address as the username.
  4. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    I was thinking of the same thing... so put my vote down for this one too.
  5. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    I've had members do this- I think this is something aMember can do quickly- send a support ticket to them.

    David
  6. cosmode

    cosmode New Member

    Joined:
    Apr 3, 2008
    Messages:
    3
    i would also like to know how to do this.
  7. jbround39

    jbround39 aMember Pro Customer

    Joined:
    Mar 20, 2008
    Messages:
    61
    Just fyi, here's how you do it.

    You need to make two modifications:
    1. common.inc.php function generate_login:
    change this:
    function generate_login($vars='') {
    global $db, $config;
    $vars = (array)$vars;

    to
    function generate_login($vars='') {
    global $db, $config;
    $vars = (array)$vars;
    return $vars;

    2. signup.php function validate_payment_form()

    change this :
    if (preg_match($preg, $vars['login'])){
    $error[] = $config['login_disallow_spaces'] ?
    _SIGNUP_INVALID_USERNAME_W_SPACES : _SIGNUP_INVALID_USERNAME;
    } elseif (strlen($vars['login']) < $config['login_min_length']){
    $error[] = sprintf(_SIGNUP_INVALID_USERNAME_2,$config['login_min_length']);
    } elseif (!$member_id=$db->check_uniq_login($vars['login'], $vars['email'],
    $vars['pass0'], 1)){
    $error[] = sprintf(_SIGNUP_INVALID_USERNAME_3,$vars[login]);
    }

    to

    if (!$member_id=$db->check_uniq_login($vars['login'], $vars['email'],
    $vars['pass0'], 1)){
    $error[] = sprintf(_SIGNUP_INVALID_USERNAME_3,$vars[login]);
    }

    3 notes:

    1. I changed my login field in my database to be 64 characters instead of 32, some people have long email addresses.
    2. You have to have amember pro to do this yourself, you can't edit the php in the encrypted free version.
    3. You should make a change in the admin cp (setup/config->global) to allow amember to automatically assign the login (that will make the common.inc.php change above auto assign email address as login).
  8. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Have you found this impacts anything like reporting, searching, etc? (especially the field length extension)
  9. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    It is useful to use the email as username for a non interactive site- however I don't think you should do it if you are planning on adding a forum or allowing members to comment on your blog.

    David
  10. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    very good point, consideration for downstream 3rd party app integration that does not support special characters could be a deal breaker..

    Perhaps an alternative is to accomplish the same goal is to:

    1) Only ask for email during signup
    2) Assign userid name as whatever is to the left of the @ ({username}@whatever.com) for compatiability (this obviously has an issue if there are 2 users frank@hotmail and frank@gmail that would need to get sorted)
    3) Modify the login post so that it allows logging in via member id or email (checking for @ in the username as a determination of which to check)
  11. kirkward

    kirkward New Member

    Joined:
    Feb 12, 2008
    Messages:
    15
    Has this issue been answered in a way that allows the use of email as username?

    I am converting to aMember from a script that uses email as user name and would like to import my existing members in a way that allows them to continue using their email as a username.

    Kirk
  12. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    You may want to test it with a test import (1 user), but since you are importing you might be ok since you can just set the username in your import file to be the email (so email and username fields would be the same.

    The obviously does not solve the issue for NEW users, but existing might just be ok.
  13. speeke

    speeke New Member

    Joined:
    Jan 2, 2009
    Messages:
    3
    I was just wondering whether an improved system for adding email addresses as usernames has been adopted yet?

    The following link:

    http://www.sitepoint.com/blogs/2008/12/23/11-ways-to-enhance-your-web-application/

    lists as its first point the recommendation to "use email addresses for usernames", based on a number of studies.

    I understand the concern of aMember Pro integration with other software, but surely the email address could be used for the initial aMember Pro login, and then the first part of the email address or, preferably, another username could be generated (either automatically or via user input) for forums etc.

    Also, I am concerned about future aMember Pro upgrades, and the hassle of having to redo all of the customization currently required to allow email addresses to be used as usernames.

    Thank you.
  14. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    You can tell amember to create the username for them, this is generated from the email.

    David
  15. speeke

    speeke New Member

    Joined:
    Jan 2, 2009
    Messages:
    3
    David,

    My question was whether aMember Pro allows the username to be the member's email address.

    And, if so, how that impacts on logins to forum plugins etc.
  16. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    speeke,

    Out of the box aMember does not use email as the username. You can, however, modify it so that it does so. There are some downsides, as you point out, such as potential compatibility issues with 3rd party applications you are integrating with.
  17. salem

    salem aMember Pro Customer

    Joined:
    Jan 14, 2009
    Messages:
    15
    Member ID OR Email Address

    Skippybosco, how does one permit login "via member id or email?" I was told by support this is not possible "out of the box."

    I would like my login page to only show two boxes:
    1) Member ID OR Email Address
    2) Password

    I am doing a "mass import" from a different membership program that only required email and password to login. In the new system I will also have a forum so I want to initially populate the database with 1) email (existing), 2) password (existing) 3) Member ID (I will generate random password for each person and explain how they can change... but if they never change it I want them to be able to login in the manner in which they are currently accustomed - email and password)

    Thank you for any thoughts.
  18. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    The way I have seen most folks do it is to use the email address as the username.

    To do this you would need to modify the .js that checks the field during signup as well as modifying a few of the templates to remove the username reference.
  19. toph

    toph New Member

    Joined:
    Mar 13, 2009
    Messages:
    2
    I ran into an issue where if the user decides to change their profile email, the login email is still the old email. Anyone know which file(s) to edit so that the login email is always the same as their profile email?
  20. toph

    toph New Member

    Joined:
    Mar 13, 2009
    Messages:
    2
    This is working for me so far (with help from support Andrey, Anton and others) and if there's anything missing or if there's code conflict that we missed, please chime in:

    1. enable 'Generate Login' option at
    aMember CP -> Setup/Configuration (Generate Login)

    2. enable 'Require Unique Email' option
    aMember CP -> Setup/Configuration (Require Unique Email)


    3. edit file amember/common.inc.php, find function 'generate_login'

    and after '$vars = (array)$vars;' insert:
    PHP:
    if ($vars['email']) return $vars['email'];
    4. edit getLoginRegex() in common.inc.php to this (the part after the question mark is a bit hacked and can probably be improved):

    PHP:
    function getLoginRegex(){
        global 
    $config;
        return 
    $config['login_disallow_spaces'] ? 
            
    '/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/' :
            
    '/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/';
    }

    5. Add this hook into site.inc.php (renamed from site-dist.inc.php)

    PHP:
    function cust_su($member_id$oldmember,$newmember) {
           global 
    $db;
           If (
    $oldmember['email']!=$newmember['email']) {
                   
    $user $db->get_user($member_id);
                   
    $user['login'] = $newmember['email'];
                   
    $db->update_user($member_id$user);
           }
           return 
    '';
    }

    setup_plugin_hook('subscription_updated''cust_su');

Share This Page