Advertisement
sanjiisan

Untitled

Sep 5th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2.  
  3. class WrongPasswordException extends Exception
  4. {
  5. public function __construct($message = "", $code = 0, Throwable $previous = null)
  6. {
  7. parent::__construct($message, $code, $previous);
  8. }
  9. }
  10.  
  11. function regexCheckPassword($password)
  12. {
  13.  
  14. $first = preg_match('/^\w{10,15}$/', $password);
  15. $second = preg_match('/[a-z]/', $password);
  16. $third = preg_match('/[A-Z]/', $password);
  17. $last = preg_match('/[A-Z]{2}|[a-z]{2}/', $password);
  18.  
  19. if (!$first) {
  20. throw new WrongPasswordException('Twoje hasło jest za krótknie');
  21. }
  22.  
  23. if (!$second) {
  24. throw new WrongPasswordException('W Twoim haśle brakuję MAŁEJ litery');
  25. }
  26.  
  27.  
  28. if (!$third) {
  29. throw new WrongPasswordException('W Twoim haśle brakuję DUŻEJ litery');
  30. }
  31.  
  32.  
  33. if ($last) {
  34. throw new WrongPasswordException('W Twoim haśle są 2 duże lub małe litery obok siebie');
  35. }
  36.  
  37. echo 'Hasło ustawione!';
  38. }
  39.  
  40. if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['pass'])) {
  41. $pass = trim($_POST['pass']);
  42.  
  43. try {
  44. regexCheckPassword($pass);
  45. } catch (WrongPasswordException $exception) {
  46. echo 'Błąd w linijce: ' . $exception->getLine() . '<br>';
  47. echo 'Błąd w pliku: ' . $exception->getFile() . '<br>';
  48. echo 'Komunikat: ' . $exception->getMessage() . '<br>';
  49. }
  50. }
  51.  
  52. ?>
  53.  
  54. <form method="post">
  55. <input type="text" name="pass">
  56.  
  57. <input type="submit" value="Sprawdź hasło">
  58. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement