Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class WrongPasswordException extends Exception
- {
- public function __construct($message = "", $code = 0, Throwable $previous = null)
- {
- parent::__construct($message, $code, $previous);
- }
- }
- function regexCheckPassword($password)
- {
- $first = preg_match('/^\w{10,15}$/', $password);
- $second = preg_match('/[a-z]/', $password);
- $third = preg_match('/[A-Z]/', $password);
- $last = preg_match('/[A-Z]{2}|[a-z]{2}/', $password);
- if (!$first) {
- throw new WrongPasswordException('Twoje hasło jest za krótknie');
- }
- if (!$second) {
- throw new WrongPasswordException('W Twoim haśle brakuję MAŁEJ litery');
- }
- if (!$third) {
- throw new WrongPasswordException('W Twoim haśle brakuję DUŻEJ litery');
- }
- if ($last) {
- throw new WrongPasswordException('W Twoim haśle są 2 duże lub małe litery obok siebie');
- }
- echo 'Hasło ustawione!';
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['pass'])) {
- $pass = trim($_POST['pass']);
- try {
- regexCheckPassword($pass);
- } catch (WrongPasswordException $exception) {
- echo 'Błąd w linijce: ' . $exception->getLine() . '<br>';
- echo 'Błąd w pliku: ' . $exception->getFile() . '<br>';
- echo 'Komunikat: ' . $exception->getMessage() . '<br>';
- }
- }
- ?>
- <form method="post">
- <input type="text" name="pass">
- <input type="submit" value="Sprawdź hasło">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement