Guest User

functions array

a guest
Sep 6th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?php
  2. function checkPassword($pwd) {
  3. $errors = array();
  4. $errors['status'] = 0;
  5. if (strlen($pwd) < 8) {
  6. $errors['status'] = 1;
  7. $errors['message'] = '{"Status":"Failed","error_message":"Password Must be 8 characters long."}';
  8. }
  9.  
  10. if (!preg_match("#[0-9]+#", $pwd)) {
  11. $errors['status'] = 1;
  12. $errors['message'] = '{"Status":"Failed","error_message":"Password Must include atleast one number!"}';
  13. }
  14.  
  15. if (!preg_match("#[a-zA-Z]+#", $pwd)) {
  16. $errors['status'] = 1;
  17. $errors['message'] = '{"Status":"Failed","error_message":"Password Must include atleast one letter!"}';
  18. }
  19.  
  20. return $errors;
  21. }
  22.  
  23. function checkUsername($username){
  24. $user_array = array();
  25. $user_array['pass_status'] = 0;
  26.  
  27. if(strlen($username) < 6 ){
  28. $user_array['pass_status'] = 1;
  29. $user_array['pass_message'] = '{"Status":"Failed","error_message":"Minimum Password length must be 6 characters or greater."}';
  30. }
  31. if(strlen($username) > 20){
  32. $user_array['pass_status'] = 1;
  33. $user_array['pass_message'] = '{"Status":"Failed","error_message":"Password length must not exceed 20 characters."}';
  34. }
  35. if ( preg_match('/\s/',$username) ){
  36. $user_array['pass_status'] = 1;
  37. $user_array['pass_message'] = '{"Status":"Failed","error_message":"Space is not allowed in username."}';
  38. }
  39. if (preg_match('/[\'^£$%&*()}{@#~?><>,|=+¬-]/', $username)){
  40. $user_array['pass_status'] = 1;
  41. $user_array['pass_message'] = '{"Status":"Failed","error_message":"Special Characters are not allowed in username"}';
  42. }
  43. return $user_array;
  44. }
  45.  
  46.  
  47.  
  48. $password = "12am3456";
  49.  
  50. $u = "sahilaa12";
  51.  
  52. $user = checkUsername($u);
  53.  
  54. $arr = checkPassword($password);
  55.  
  56. print_r($user);
  57.  
  58. ?>
Add Comment
Please, Sign In to add comment