IlaminiAyebatonyeDagogo Posted December 9, 2013 Share Posted December 9, 2013 Am Creating a login Script and i do not want users to put in number or alpha numeric characters in the username field and i use the the ctype_alnum function the problem is that the validation is also affecting the password field below is login script. <div id="login"> <?php if(isset($_POST["login"])&&(empty($_POST["username"])||empty($_POST["password"]))) { echo"<p class='style1' style='background:yellow;' > Please You Have to Provide a Valid Username and password</p>"; $staff=false;}?> <form action="<?php $_SERVER["PHP_SELF"] ?>" method="post"> <label style="font-style:bold;color:#FF9900;" ><h2>UserName:</h2> </label> <?php if(isset($_POST["login"])&&(empty($_POST["username"]))) { echo"Your User Name is Required";$staff=false; } elseif(ctype_alnum($_POST["username"])==true) { echo"You are allowed to put in Numbers<br>"; $staff=false; } ?> <input size="40" type="text" name="username" placeholder="UserName"/><br><br> <label style="font-style:bold;color:#FF9900;" ><h2>Password:</h2> </label> <?php if(isset($_POST["login"])&&(empty($_POST["password"]))) { echo"Your Password is Required";$staff=false; } ?> <input style="radius:6;" size="40" type="password" placeholder="Password" name="password"/><br></div> <input type="submit" width="25px" value="Login" name="login"/> </form> so please help check the code for errors and how to limit the ctype_alnum validation to just the username field. Quote Link to comment Share on other sites More sharing options...
IlaminiAyebatonyeDagogo Posted December 9, 2013 Author Share Posted December 9, 2013 Any help Please Help Quote Link to comment Share on other sites More sharing options...
IlaminiAyebatonyeDagogo Posted December 9, 2013 Author Share Posted December 9, 2013 Any one there Quote Link to comment Share on other sites More sharing options...
IlaminiAyebatonyeDagogo Posted December 9, 2013 Author Share Posted December 9, 2013 Where is my boss pls come to my AID Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted December 9, 2013 Solution Share Posted December 9, 2013 i do not want users to put in number or alpha numeric characters in the username field Then what characters do you want them to use? You know alpha-numeric covers A-Z and 0-9 right? So if you disallow it you restrict people to international or symbol characters. I'm going to run on the assumption you mean you want users to only use alpha-numeric characters, in which case you'd do: if (!ctype_alnum($_POST['username'])){ echo "You may only use alpha-numeric characters"; $staff=false; } If you want the same restriction on the password, you'd do the same check. If you don't want the restriction then do nothing. Right now your only restriction on the password is that it is not empty. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.