html - PHP form validation using preg_match for password checks -


this general question on password form validation , using combination of uppercase, lowercase, numbers , characters used.

research has showed preg_match required validate password (or whatever variable use): (preg_match("/^.(?=.{8,})(?=.[0-9])(?=.[a-z])(?=.[a-z]).*$/")

though how how integrate if statement below? i've tried combining them using && though seems ignore preg_match part. if(($pass == $pass2) && (preg_match("/^.(?=.{8,})(?=.[0-9])(?=.[a-z])(?=.[a-z]).*$/"))

any advice appreciated.

<?php  require "dbconn.php";  $username = ($_get['username']); $email = ($_get['email']); $pass = ($_get['pwd1']); $pass2 = ($_get['pwd2']); $usn = ($_get['schoolnumber']);  $matching = 0;  if($pass == $pass2) { echo "<script type='text/javascript'> window.alert('your details have been    registered, please proceed login new credentials!')</script>"; echo '<script>javascript:window.close();</script>';   $query = "insert customer values     ('".$username."','".$email."','".$pass."','face1.jpg','".$usn."','n')";  $results = mysql_query($query) or die (mysql_error());  $results1 = mysql_query($query1) or die (mysql_error()); } else{  header('location:register.php?matching=1');  } ?> 

preg_match requires 2 arguments pattern , string test. plus i'm not sure if regular expression using work anyway. try like.

$pattern = '/(?=.*\d)(?=.*[a-z])(?=.*[a-z]).{8,}/'; if (($pass1 == $pass2) && preg_match($pattern, $pass1)) {     ... } 

you need match against 1 of passwords because should ($pass1 == $pass2) fail preg_match isn't preformed.

the regex above checks password @ least 8 characters long , contains @ least 1 of each of lowercase, uppercase , number


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -