Web Hosting Talk







View Full Version : Form Validation In PHP


latheesan
12-07-2006, 08:43 PM
I need to do 2 simple form validation.

1. Check if there is invalid charaters inside $_POST["username"]; such as % ^ * ( " ! ? ) , . etc...

2. Check the entered $_POST["password"]; strength and give the strength in %. for e.g. if the entered password is something like abcd1234WoW, give strength as 100% or close.

How can i do this? Thanks for any help you offer me.

horizon
12-07-2006, 09:19 PM
If you currently have some codings I could see, I might be able to help you out here. ;)

brendandonhu
12-07-2006, 10:10 PM
ctype_alnum() and crack_check()

astellar
12-08-2006, 04:51 PM
1. Check if there is invalid charaters inside $_POST["username"]; such as % ^ * ( " ! ? ) , . etc...
try something like

if(preg_match("/\W/i", $_POST["username"])) //bad user name

2. Check the entered $_POST["password"]; strength and give the strength in %. for e.g. if the entered password is something like abcd1234WoW, give strength as 100% or close.

the same idea


$strength = 0;

// do we have digits?

if(preg_match("/[\d]+/i", $_POST["password"])) $strength += 33; //add 33%

// do we have different letter case?

if(strtolower($_POST["password"]) != $_POST["password"]) $strength += 33; //add 33%

// do we have other characters in password?

if(preg_match("/[^\w\d]+/i", $_POST["password"])) $strength += 34; //add 34%


I can be bad about last regexp, you can find correct pattern syntax here (http://look4docs.com/docs/php/5.1.4/reference.pcre.pattern.syntax.html)

Jatinder
12-09-2006, 08:21 AM
Take a look at http://x-code.com/vdaemon_web_form_validation.php