]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/AbstractPassword.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Copyright © 2003-2024 The Galette Team
8 * This file is part of Galette (https://galette.eu).
10 * Galette is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * Galette is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
24 namespace Galette\Core
;
27 use Galette\Entity\Adherent
;
32 * @author Frédéric Jacquot <gna@logeek.com>
33 * @author Georges Khaznadar (password encryption, images) <georges@unknow.org>
34 * @author Johan Cwiklinski <johan@x-tnd.be>
37 abstract class AbstractPassword
39 /** Default password size */
40 public const DEFAULT_SIZE
= 8;
42 protected string $chars = 'abcdefghjkmnpqrstuvwxyz0123456789';
43 protected ?
string $hash = null;
44 protected string $new_password;
47 * Generates a random password based on default salt
49 * @param int|null $size Password size (optional)
51 * @return string random password
53 public function makeRandomPassword(int $size = null): string
55 $size = $size ??
static::DEFAULT_SIZE
;
58 while ($i <= $size - 1) {
59 $num = mt_rand(0, strlen($this->chars
) - 1) %
strlen($this->chars
);
60 $pass .= substr($this->chars
, $num, 1);
67 * Generates a new password for specified member
69 * @param int $id_adh Member identifier
73 abstract public function generateNewPassword(int $id_adh): bool;
76 * Remove expired passwords queries (older than 24 hours)
80 abstract protected function cleanExpired(): bool;
83 * Retrieve new password for sending it to the user
85 * @return string the new password
87 public function getNewPassword(): string
89 return $this->new_password
;
97 public function getHash(): string
105 * @param string $password Password
109 protected function setPassword(string $password): self
111 $this->new_password
= $password;
118 * @param string $hash Hash
122 protected function setHash(string $hash): self