views:

46

answers:

3

how can i check if the password is more than 6 letters using php, this is for my registration form. :)) thanks

A: 

You can use the strlen() function.

greg0ire
+2  A: 
if(strlen(trim($password)) > 6){
  // do something here
}
Sabeen Malik
cheers!!! :)) excuse my dumbess, im kind of new to this
getaway
haha dont worry about it, we were all new and dumb once :)
Sabeen Malik
looooool :)) thanks
getaway
I'm not sure I'd do the `trim()`. It might be useful if people are likely to paste passwords rather than typing them, but it might prevent enterprising users from putting a space on the end of their password.
staticsan
thanksm can i just ask you how do you check for unwanted characters in the username, i only want letters, numbers, and underscores, and no spaces obviously
getaway
Was on my way out, saw your comment and did a quick search, this should help `if((ereg("^[a-zA-Z0-9_\-]+$", $your_variable_here)) { // value username }`
Sabeen Malik
@staticsan .. i think you have a very valid point, my main reason of using it was to disallow people from just entering 6 spaces in there. something to think about for getaway :)
Sabeen Malik
cheers! thank your a genius sebeeen
getaway
Lazy users are more likely to type `123456` or `password` as a bad password rather than six spaces. If you want to prevent bad passwords, you should do it properly: check for all the things that make a password "strong", assign points for each check and then require a minimum point score corresponding to most checks passing.
staticsan
+1  A: 

I think you will find this very usefull:

http://www.phpro.org/tutorials/Validating-User-Input.html

Good luck, Please tell me if you need any help with it!

Trufa
I would definitely go with Sabeen´s answer, if you want to read further, read my answer. :)
Trufa