Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. abDc#E0%F9$845,
  2. abDc#E0%F9$8y6,
  3. abDc#E0981,
  4. #ab1DcE09w1234 **(4 sequential numbers)**,
  5. #ab1111DcE09,
  6. E$ab1Dc098,
  7. 1$Eab1Dc0989,
  8. T3$s7p4s$123,
  9. T1234$stPass **(4 sequential numbers)**
  10.  
  11. testpass,
  12. abDc#E0%F9$8y67 (15 characters),
  13. t3stpass,
  14. te$stpass,
  15. TestPass,
  16. T3$stpass
  17.  
  18. if (preg_match('/^(?=.*[A-Z])(?=(?:.*d){4,})(?=.*[!@$%^&*()_+=-]).{6,14}$/', $string)) {
  19. // remove all non digit
  20. $tmp = preg_replace('/D+/', '', $string);
  21. if (preg_match('/0123|1234|2345|3456|4567|5678|6789|3210|4321|5432|6543|7654|8765|9876|0000|1111|2222|3333|4444|5555|6666|7777|8888|9999/', $string)) {
  22. echo "Failedn";
  23. }
  24. echo "Passn";
  25. } else {
  26. echo "Failedn";
  27. }
  28.  
  29. (?=.*[A-Z]) : at least one uppercase
  30. (?=(?:.*d){4,}) : at least 4 digits
  31. (?=.*[!@$%^&*()_+=-]) : at least one special character
  32. .{6,14} : from 6 to 14 character long
  33.  
  34. function validate_password($password){
  35.  
  36. if(empty($password))
  37. return false;
  38.  
  39. if(strlen($password) < 4 || strlen($password) > 14)
  40. return false;
  41.  
  42. $uppercase_test = preg_match('#[A-Z]+#', $password);
  43.  
  44. //include special charactors that you want
  45. $special_test = preg_match('#[!@$%^&*()_+=-]+#', $password);
  46.  
  47. $nonsequencial_number_test = !preg_match('#(d)\1{4,}#', $password);
  48.  
  49. if($uppercase_test && $special_test && $nonsequencial_number_test){
  50. return true;
  51. }
  52.  
  53. return false;
  54.  
  55. }
  56. var_dump(validate_password('abDc#E0%F9$8y6'));
  57.  
  58. <?php
  59. if (isset($_GET['string'])) {
  60. if ($_GET['string'] != '') {
  61. $string = $_GET['string'];
  62. } else {
  63. echo "Empty string.";
  64. }
  65. }
  66. ?>
  67. <pre>
  68. <html>
  69. <head>
  70. <title>Regular Expression Tester</title>
  71. </head>
  72. <body>
  73. <form action="" method="get">
  74. <input type="text" name="string" />
  75. <input type="submit" value="Send" />
  76. </form>
  77. </pre>
  78. <?php
  79. if (isset($_GET['string'])) {
  80.  
  81. if(strlen($string) >= 6 && strlen($string) <= 14) { // length between 6 and 14
  82. echo "Size between 6 and 14: <b><span style="color:green;">OK</span></b>", "<br>";
  83.  
  84. if (preg_match('#[A-Z]+#', $string)) { // one or more uppercase chars
  85. echo utf8_decode("At least one uppercase: <b><span style="color:green;">OK</span></b>"), "<br>";
  86.  
  87. if (preg_match('#(?=.*[0-9]{1}.*[0-9]{1}.*[0-9]{1}.*[0-9]{1})#', $string)) { // it has at least 4 numbers anywhere
  88. if (!preg_match('#(0123|1234|2345|3456|4567|5678|6789|3210|4321|5432|6543|7654|8765|9876|0000|1111|2222|3333|4444|5555|6666|7777|8888|9999)#', $string)) { // sequential numbers
  89. echo utf8_decode("4 non-sequential numbers: <b><span style="color:green;">OK</span></b>"), "<br>";
  90.  
  91. if (preg_match('#[!@$%^&*()_+=-]+#', $string)) { // special chars
  92. echo utf8_decode("At least one special character: <b><span style="color:green;">OK</span></b>"), "<br>";
  93. echo utf8_decode("<br>$string <b><span style="color:green;">PASSED</span></b>");
  94. exit;
  95.  
  96. } else {
  97. echo utf8_decode("At least one special character: <b><span style="color:red;">FAILED</span></b>"), "<br>";
  98. }
  99.  
  100. } else {
  101. echo utf8_decode("4 non-sequential numbers: <b><span style="color:red;">FAILED</span></b>"), "<br>";
  102. }
  103. } else {
  104. echo utf8_decode("4 non-sequential numbers: <b><span style="color:red;">FAILED</span></b>"), "<br>";
  105. }
  106.  
  107. } else {
  108. echo utf8_decode("At least one uppercase: <b><span style="color:red;">FAILED</span></b>"), "<br>";
  109. }
  110.  
  111. } else {
  112. echo "Size between 6 and 14: <b><span style="color:red;">FAILED</span></b>", "<br>";
  113. }
  114.  
  115. echo utf8_decode("<br>$string <b><span style="color:red;">DIDN'T PASS</span></b>");
  116. }
  117. ?>
  118. <pre>
  119. </body>
  120. </html>
  121. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement