Project:User Import
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

#1

By changing the preg_replace from:

<?php

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

to
<?php

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

I was able to import email address as the username.

#2

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

#3

Version:4.7.x-1.x-dev» 5.x-1.x-dev
Status:active» needs review

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.

AttachmentSize
user_import_username_email_address.patch 784 bytes

#4

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

#5

Does this patch work with LoginToboggan ?

#6

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.

#7

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:{}');

#8

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

#9

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

AttachmentSize
user_import_username_email_address.patch 790 bytes

#10

Category:feature request» bug report
Priority:normal» critical

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

#11

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 ?

#12

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

#13

Status:needs review» fixed

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

#14

Status:fixed» closed (fixed)

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