Drupal allows usernames to be email address, why can't I import them that way? Looks like a simple tweak to the sanitize function but wanted to ask unless there were other issues.

Comments

emackn’s picture

By changing the preg_replace from:

        // username cannot contain an illegal character
        $username = preg_replace('/[^a-zA-Z0-9 ]/', ' ', $username);

to

        // username cannot contain an illegal character
        $username = preg_replace('/[^a-zA-Z0-9@\. ]/', ' ', $username);

I was able to import email address as the username.

robert castelo’s picture

Good idea, I'll add it to the next release.

mfb’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new784 bytes

This patch allows typical email address characters: dot, underscore, hyphen and plus sign. within the preg brackets, of these only hyphen is a metacharacter which needs to be escaped.

mfb’s picture

marked http://drupal.org/node/165717 as duplicate

coupet’s picture

Does this patch work with LoginToboggan ?

mfb’s picture

I am using it with logintoboggan. However I have not tested it with the logintoboggan setting to force usernames to not be email addresses. Obviously in my case I don't want to do this.

coupet’s picture

name is varchar(60) and mail varchar(64) are of different sizes.

Should we generate username based on email, firstname, lastname or other criteria; instead of inserting email in the name field?

We may want to think about OpenID support as planned here http://drupal.org/node/162356th

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
`uid` int(10) unsigned NOT NULL default '0',
`name` varchar(60) NOT NULL default '',
`pass` varchar(32) NOT NULL default '',
`mail` varchar(64) default '',
`mode` tinyint(4) NOT NULL default '0',
`sort` tinyint(4) default '0',
`threshold` tinyint(4) default '0',
`theme` varchar(255) NOT NULL default '',
`signature` varchar(255) NOT NULL default '',
`created` int(11) NOT NULL default '0',
`access` int(11) NOT NULL default '0',
`login` int(11) NOT NULL default '0',
`status` tinyint(4) NOT NULL default '0',
`timezone` varchar(8) default NULL,
`language` varchar(12) NOT NULL default '',
`picture` varchar(255) NOT NULL default '',
`init` varchar(64) default '',
`data` longtext,
PRIMARY KEY (`uid`),
UNIQUE KEY `name` (`name`),
KEY `created` (`created`),
KEY `access` (`access`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`uid`, `name`, `pass`, `mail`, `mode`, `sort`, `threshold`, `theme`, `signature`, `created`, `access`, `login`, `status`, `timezone`, `language`, `picture`, `init`, `data`) VALUES
(0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, NULL, '', '', '', NULL),
(1, 'admin', 'eb06eff7259e802e5b331eb72f23e96c', 'coupet@yahoo.com', 0, 0, 0, '', '', 1187401438, 1187631257, 0, 1, '0', '', '', 'coupet@yahoo.com', 'a:0:{}');

goose2000’s picture

Thanks, I am using this now - need email logins to work with IMAP servers!

mfb’s picture

StatusFileSize
new790 bytes

Here's a revised patch -- drupal core does not allow "+" in user names (although it is a valid character in e-mail addresses).

mfb’s picture

Category: feature » bug
Priority: Normal » Critical

Marking this as a critical bug since dash, dot and underscore really should be allowed in usernames.

giorgosk’s picture

I have a case where I want to allow usernames with parentheses ( )
if I tweaked the code to do it, would it create a problem ?

mfb’s picture

Not a good idea since drupal core doesn't allow parentheses in user names.

robert castelo’s picture

Status: Needs review » Fixed

Fixed in 5.x-2.0-beta1, please re-open this issue if you can still replicate the bug.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.