Jump to content

[SOLVED] forcing lowercase in register form


stelthius

Recommended Posts

Hello again guys :)

 

 

I'm trying to force the username field in my registration form to all lowercase so the users cant register a name with uppercase in it e.g. TesterAccount

 

 

So far i have tried using CSS which didnt work

 

text-transform: lowercase; 
text-transform: uppercase; 
text-transform: capitalize;

 

So then i tried using PHP's way of doing it strtolower but i cant seem to get it to work below is my registration form firleds,

 

<?
if($form->num_errors > 0){
   echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST" enctype="multipart/form-data">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" id="username" name="user" onchange="toggle_username('username');" maxlength="30" value="<? echo $form->value("user"); ?>">
</td><td><div id="username_exists"></div></td></tr></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" id="pass" onChange="toggle_pass('pass')" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?><div id="password_strength"> </div>
<tr><td>Confirm Password :</td><td><input type="password" name="pass2" id="pass2" maxlength="30" value="<? echo $form->value("pass2"); ?>"></td><td><? echo $form->error("pass2"); ?></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr>
<td>Avatar:<input type="file" name="avatar"><? echo $form->error("avatar"); ?></td>
<tr><td> <img src="CaptchaSecurityImages.php" /><br />
<label for="security_code">Security Code: </label>
<input id="security_code" name="security_code" type="text" /><br />
<? echo $form->error("security_code"); ?> </td></tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" value="Join!"></td></tr>
<tr><td colspan="2" align="left"><a href="index.php">Back to Main</a></td></tr>
</table>

 

 

Any tips or ideas are great thanks guys again :D

 

 

Rick

Link to comment
Share on other sites

I tried to but i never succeeded, im relativly new to php and i tried what i assumed would work. i added it to my register function

 

 

 

function procRegister(){
      global $session, $form;
      if(ALL_LOWERCASE){
         $_POST['user'] = strtolower($_POST['user']);

 

And i really dont want to be using javascript to do it.

 

Rick

 

 

Link to comment
Share on other sites

I would not use javascript either, but the above looks fine to me...is not actually going to lowercase? I guess what I am trying to say is, it does not matter how it looks on the form as long as you use strtolower before you insert it into the DB.

 

But just an FYI, if when validating a user for logging in, if you check the data via the database instead of PHP it is case insensitive. So yea it really should not matter if it is lower or upper, at least in my opinion =)

Link to comment
Share on other sites

Ok here are my registration parts,

 

This processes the registration :

 

   function procRegister(){
      global $session, $form;
      
      if(ALL_LOWERCASE){
         $_POST['user'] = strtolower($_POST['user']);
      }
      
      $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['pass2'], $_POST['email'], $_FILES['avatar']['name'], $_FILES['avatar']['size'], $_FILES['avatar']['type'], $_FILES['avatar']['tmp_name'], $_POST['security_code']);     
      
      if($retval == 0){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = true;
         header("Location: ".$session->referrer);
      }
      
      else if($retval == 1){
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
      
      else if($retval == 2){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = false;
         header("Location: ".$session->referrer);
      }
   }

 

 

And this is what checks if the name is banned etc etc etc

 

 

function register($subuser, $subpass, $subpass2, $subemail, $avatar_name, $avatar_size, $avatar_type, $avatar_tmpname, $subsecurity_code){
      global $database, $form, $mailer;  //The database, form and mailer object
      
      /* Username error checking */
      $field = "user";  //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
         $form->setError($field, "* Username not entered");
      }
      else{
         /* Spruce up username, check length */
         $subuser = stripslashes($subuser);
         if(strlen($subuser) < 5){
            $form->setError($field, "* Username below 5 characters");
         }
         else if(strlen($subuser) > 30){
            $form->setError($field, "* Username above 30 characters");
         }
         /* Check if username is not alphanumeric */
         else if(!eregi("^([0-9a-z])+$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
         /* Check if username is reserved */
         else if(strcasecmp($subuser, GUEST_NAME) == 0){
            $form->setError($field, "* Username reserved word");
         }
         /* Check if username is already in use */
         else if($database->usernameTaken($subuser)){
            $form->setError($field, "* Username already in use");
         }
         /* Check if username is banned */
         else if($database->usernameBanned($subuser)){
            $form->setError($field, "* Username banned");
         }
      }

      /* Password error checking */
      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      else{
         /* Spruce up password and check length*/
         $subpass = stripslashes($subpass);
         if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
         }
         /* Check if password is not alphanumeric */
         else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }      
      }
     /* Password2 error checking */
    $field = "pass"; //Use field name for password
    $field2 = "pass2"; // Second field for password
    if(!$subpass2){
    $form->setError($field2, "* Password not entered");
    }
      else{
     //$subpass = stripslashes($subpass);
     //$subpass2 = stripslashes($subpass2);
        if($subpass!==$subpass2){
           $form->setError($field2, "* Passwords does not match");
         }    
    }

 

 

To be honest thats the only two pices of code i can think of that would stop it form going to all lower case,

 

Rick

Link to comment
Share on other sites

But that is really not what I am after, Where does the data get inserted into the database?

 

Also you send them to "session->register" but no where in that register function are you setting the variables to session data....or even updating the $_POST data...that just confuses me...

Link to comment
Share on other sites

sorry i fgot to paste that part, sorry,

 

/* No errors, add the new account to the */
      else{
         if($database->addNewUser($subuser, md5($subpass), md5($subpass2), $subemail, $avatar_name)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser,$subemail,$subpass);
            }
            /*** This is new ************************/
            if(AUTO_LOGIN){
               /* Username and password correct, register session variables */
               $this->userinfo  = $database->getUserInfo($subuser);
               $this->username  = $_SESSION['username'] = $this->userinfo['username'];
               $this->userid    = $_SESSION['userid']   = $this->generateRandID();
               $this->userlevel = $this->userinfo['userlevel'];
      
               /* Insert userid into database and update active users table */
               $database->updateUserField($this->username, "userid", $this->userid);
               $database->addActiveUser($this->username, $this->time);
               $database->removeActiveGuest($_SERVER['REMOTE_ADDR']);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.