Support Forums

Mod: Strip bad characters from Username

This is a discussion on Mod: Strip bad characters from Username within the Modules / Plugins / Modifications forums, part of the Developer Forums category; I did this so my site's usernames would not be email or web addresses or contain any special characters. This ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 05-29-2008, 02:40 AM   #1
Senior Member
 
Join Date: Jun 2007
Posts: 110
Rep Power: 13
crystal is on a distinguished road
Smile Mod: Strip bad characters from Username

I did this so my site's usernames would not be email or web addresses or contain any special characters. This mod will strip out all bad characters while the user is typing. It will allow only A-Z, 0-9, and underscore (_) to be typed into the username field.

Open templates/default/user/userjoin.tpl

Find this (lines 1-28)
Code:
{literal}
<script language="JavaScript" type="text/javascript">
<!-- //
function checkform(frm) {
  {/literal}
     {$validation}
  {literal}
}
function showterms(){
	newwin=window.open("terms.php","Terms","menubar=no, scrollbars=yes, width=420, height=380, directories=no,location=no,resizable=yes,status=no,toolbar=no");
}
function new_freecap()
{
	// loads new freecap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freecap image\nSubmit the form and a new freecap will be loaded");
	}
}
//-->
</script>
{/literal}
Replace with this:
Code:
{literal}
<script language="JavaScript" type="text/javascript">
<!-- //
function checkform(frm) {
  {/literal}
     {$validation}
  {literal}
}
function showterms(){
	newwin=window.open("terms.php","Terms","menubar=no, scrollbars=yes, width=420, height=380, directories=no,location=no,resizable=yes,status=no,toolbar=no");
}
function new_freecap()
{
	// loads new freecap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freecap image\nSubmit the form and a new freecap will be loaded");
	}
}
//Strip bad characters
var badChars = /[-?!$\\@\/\#%\^\&\*\(\)\[\]\+\{\}\`\~\=\.,\'\";:|><]/;
function checkChars(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
if(lchar.search(badChars) != -1) {
var tst = val.value.substring(0, (strLength) - 1);
val.value = tst;
   }
}
// -->
</script>
{/literal}
Find this (now around line 153):
Code:
<input name="username" type="text" id="username" value="{$username}" size="{$smarty.const.FIELD_SIZE}" />
Replace with this:
Code:
<input name="username" type="text" id="username" value="{$username}" size="{$smarty.const.FIELD_SIZE}" maxlength="30"  onKeyUp="javascript:checkChars(login.username);"/>
Note: I have added a max length of 30 to the username field. This can be changed to your preference. I recommend setting a max length for all fields.
__________________
Crystal
v4.0.8 Dev

Last edited by crystal; 05-29-2008 at 02:44 AM.
crystal is offline   Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
no username? outthere Technical Support 0 11-08-2007 09:41 PM
Using "modify ad" overrides max characters setting Avi8r v3.1 Questions & Support 3 08-18-2007 02:32 PM
How To Scrub & Replace Characters In Input Fields? bgordon v3.1 Questions & Support 5 04-15-2007 06:49 PM
Number of Characters in Title and Desc pbraz v3.1 Questions & Support 1 02-06-2007 09:50 AM
Retrieving a lost username spaceboy v3.1 Questions & Support 1 09-09-2006 06:42 PM


All times are GMT -4. The time now is 06:04 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0