oracle259 Posted July 7, 2006 Share Posted July 7, 2006 I needed to know how to create a regex to ban passwords that contain a user's given userid or email. I considered using similar_text but i'm not so familiar with that function and i think regex may be more efficient.Thanks :D Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 7, 2006 Share Posted July 7, 2006 you can just use a preg_match!!!!!<?php$username = $_POST['regusername'];$password = "/".$_POST['regpassword']."/";if (preg_match($username,$password)){ //deny completeion of registration...}else{ // carry on...}?> Quote Link to comment Share on other sites More sharing options...
oracle259 Posted July 8, 2006 Author Share Posted July 8, 2006 ok but would preg_match work for lets say the password is p.oracle259-ender and userid is oracle259? Quote Link to comment Share on other sites More sharing options...
oracle259 Posted July 8, 2006 Author Share Posted July 8, 2006 Also can i use variables like $pwd and $userid in other regex Quote Link to comment Share on other sites More sharing options...
oracle259 Posted July 8, 2006 Author Share Posted July 8, 2006 ok i read up on preg_match but the php manual recommends using strpos as it is faster. So let me know if this code would surffice:<?php$password = 'p.oracle259-ender';$userid = 'oracle259';$inpass = strpos($password, $userid);if ($incheck === true) { echo "Error: Sorry password cannot contain your set userid'";} else { encrypt password make password DB safe insert password into DB } Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 8, 2006 Share Posted July 8, 2006 Oracle259, I think it should be:if($inpass!=FALSE)Because it will return false if not found, so I don't think it will return BOOLEAN true. Quote Link to comment Share on other sites More sharing options...
BinaryStar Posted July 10, 2006 Share Posted July 10, 2006 Couldn't you also just use stristr? If you are only looking for one string within another why not? You are not really matching a pattern but just s imple string. Just a suggestion. 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.