cashflowtips Posted September 12, 2007 Share Posted September 12, 2007 i having a problem on how to check the user name and password during registration session... the input like this :- user name : admin password : admin123 /* False */ if something like this happen, the system should output error message because the password have partial words same as the user name. if can, i would like to limit it to allow only 3 consecutive letter to be same. example :- user name : admin password : admi123 /* False */ user name : admin password : adm789 /* True (allowed) */ can anybody help me here? Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/ Share on other sites More sharing options...
redarrow Posted September 12, 2007 Share Posted September 12, 2007 <?php $username="admin"; $password="admin123"; $cheek1=substr($username,0,3); $cheek2=substr($password,0,3); if($cheek1==$cheek2){ echo "Sorry the username and password have the same first three letters"; }else{ echo "Username and password are valid as the first three letters dont match"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346629 Share on other sites More sharing options...
cashflowtips Posted September 12, 2007 Author Share Posted September 12, 2007 <?php $username="admin"; $password="admin123"; $cheek1=substr($username,0,3); $cheek2=substr($password,0,3); if($cheek1==$cheek2){ echo "Sorry the username and password have the same first three letters"; }else{ echo "Username and password are valid as the first three letters dont match"; } ?> thank you for you reply... really appreciate it... i have another question. can it trace something like this :- user name : 12admin99 password : !(admin)! will it return true or false? Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346632 Share on other sites More sharing options...
kireol Posted September 12, 2007 Share Posted September 12, 2007 the above is nice. here's an alternative which would also catch a password of "theadmin" or "1admin" <?php $username="admin"; $password="admin123"; $cheek=substr($admin,0,3); if(strstr($password,$cheek) { echo "Sorry the username and password have the same first three letters"; }else{ echo "Username and password are valid as the first three letters dont match"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346636 Share on other sites More sharing options...
d.shankar Posted September 12, 2007 Share Posted September 12, 2007 You can make use of this functions to find the similarities between the username and password in percentiles.. If the similarity rate is high , then you can fail this attempt ..else success. similar_text http://www.php.net/manual/en/function.similar-text.php Levenshtein http://www.php.net/manual/en/function.levenshtein.php You can find similar_text more flexible. Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346664 Share on other sites More sharing options...
jitesh Posted September 12, 2007 Share Posted September 12, 2007 <?php $username = "admin"; $password = "admin123"; if(preg_match("/".$username."/i",$password)){ echo "Please Change Password"; }else{ echo "Password is ok"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346719 Share on other sites More sharing options...
cashflowtips Posted September 12, 2007 Author Share Posted September 12, 2007 <?php $username = "admin"; $password = "admin123"; if(preg_match("/".$username."/i",$password)){ echo "Please Change Password"; }else{ echo "Password is ok"; } ?> but how can i limit it like i mentioned above? Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346756 Share on other sites More sharing options...
jitesh Posted September 12, 2007 Share Posted September 12, 2007 <?php $username = "admin"; $password = "admin123"; $sub_username = substr($username,0,4); if(preg_match("/".$sub_username."/i",$password)){ echo "Please Change Password"; }else{ echo "Password is ok"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68948-username-password-comparison/#findComment-346764 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.