<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16525" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I am looking to alter the main user module to 
prevent more non-alphanumeric characters than drupal does by default. I added, 
as you can see, a line to prevent underscores as we have a mash up with 
Mediawiki and underscores cause a major headache. I did so by disallowing 
unicode character 005F which is a standard underscore, and I emphasise 
"standard" here: there are about 3 other underscore characters!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Is there a simple way of disallowing accented 
characters which also throw a spanner in the mediawiki machinery? I suppose I 
could always use the admin/access rules to do this. Maybe it's better than 
further hacking core. I had little choice with underscore because underscore is 
for some reason used as a wildcard character in access rules so I had to add it 
here:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>/**<BR>&nbsp;* Verify the syntax of the given 
name.<BR>&nbsp;*/<BR>function user_validate_name($name) {<BR>&nbsp; if 
(!strlen($name)) return t('You must enter a username.');<BR>&nbsp; if 
(substr($name, 0, 1) == ' ') return t('The username cannot begin with a 
space.');<BR>&nbsp; if (substr($name, -1) == ' ') return t('The username cannot 
end with a space.');<BR>&nbsp; if (strpos($name, '&nbsp; ') !== FALSE) return 
t('The username cannot contain multiple spaces in a row.');<BR>&nbsp; if 
(ereg("[^\x80-\xF7 [:alnum:]@_.-]", $name)) return t('The username contains an 
illegal character.');<BR>&nbsp; if 
(preg_match('/[\x{80}-\x{A0}'.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// Non-printable ISO-8859-1 + 
NBSP<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// 
Underscore<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'\x{FF01}-\x{FF60}'.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Full-width 
latin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'\x{FFF9}-\x{FFFD}'.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Replacement 
characters<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'\x{0}]/u',&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// NULL 
byte<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$name)) {<BR>&nbsp;&nbsp;&nbsp; return t('The username contains an illegal 
character.');<BR>&nbsp; }<BR>&nbsp; if (strpos($name, <A 
href="mailto:'@'">'@'</A>) !== FALSE &amp;&amp; !eregi(<A 
href="mailto:'@([0-9a-z](-?[0-9a-z])*.)+[a-z]{2}([zmuvtg]|fo|me)?$'">'@([0-9a-z](-?[0-9a-z])*.)+[a-z]{2}([zmuvtg]|fo|me)?$'</A>, 
$name)) return t('The username is not a valid authentication ID.');<BR>&nbsp; if 
(strlen($name) &gt; USERNAME_MAX_LENGTH) return t('The username %name is too 
long: it must be %max characters or less.', array('%name' =&gt; $name, '%max' 
=&gt; USERNAME_MAX_LENGTH));<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I mentioned a similar problem to this on this 
mailing list a few months ago and I had people coming back to me with ways in 
which the above code was not done very well. Of particular interest was this 
line:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;if (ereg("[^\x80-\xF7 [:alnum:]@_.-]", 
$name)) return t('The username contains an illegal character.');</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>As I say, this is the core user.module so this is 
on every drupal site out there. What does this line do and is it indeed coded 
poorly? In an ideal world, I would like to allow ONLY a-z, 0-9 and hyphens and 
that's it! I may even offer a project on the forum to rewrite this part of the 
module to allow only those characters. It seems better than disallowing a whole 
raft of other characters - to allow only a, b and c, so to speak.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Mashing up drupal and mediawiki causes so many 
headaches when it comes to allowable usernames and there's always that one tenth 
of a percent who absolutely MUST HAVE their username as @@|||||||| - - 
*_The__&lt;&lt;Big&gt;&gt;__Lebowski_||*&nbsp;- - |||||||||@@</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if anyone puts that into mediawiki, our server will 
go up in smoke.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Neil</FONT></DIV></BODY></HTML>