3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Abstract password for galette. The original code was found
7 * in includes/functions.inc.php
11 * Copyright © 2003-2016 The Galette Team
13 * This file is part of Galette (http://galette.tuxfamily.org).
15 * Galette is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * Galette is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
31 * @author Frédéric Jaqcuot <unknown@unknow.com>
32 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
33 * @author Johan Cwiklinski <johan@x-tnd.be>
34 * @copyright 2003-2016 The Galette Team
35 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
37 * @link http://galette.tuxfamily.org
38 * @since Available since 0.9dev - 2016-11-08
41 namespace Galette\Core
;
44 use Laminas\Db\Adapter\Exception
as AdapterException
;
45 use Galette\Entity\Adherent
;
51 * @name AbstractPassword
53 * @author Frédéric Jaqcuot <unknown@unknow.com>
54 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
55 * @author Johan Cwiklinski <johan@x-tnd.be>
56 * @copyright 2009-2016 The Galette Team
57 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
58 * @link http://galette.tuxfamily.org
59 * @since Available since 0.9dev - 2016-11-08
62 abstract class AbstractPassword
64 /** Default password size */
65 const DEFAULT_SIZE
= 8;
67 protected $chars = 'abcdefghjkmnpqrstuvwxyz0123456789';
68 protected $hash = null;
69 protected $new_password;
72 * Generates a random passord based on default salt
74 * @param int $size Password size (optionnal)
76 * @return string random password
78 public function makeRandomPassword($size = null)
84 $size = self
::DEFAULT_SIZE
;
88 while ($i <= $size-1) {
89 $num = mt_rand(0, 32) %
33;
90 $pass .= substr($this->chars
, $num, 1);
97 * Generates a new password for specified member
99 * @param mixed $arg Any argument required
103 abstract public function generateNewPassword($arg);
106 * Remove expired passwords queries (older than 24 hours)
110 abstract protected function cleanExpired();
113 * Retrieve new pasword for sending it to the user
115 * @return string the new password
117 public function getNewPassword()
119 return $this->new_password
;
125 * @return string hash
127 public function getHash()
135 * @param string $password Password
139 protected function setPassword($password)
141 $this->new_password
= $password;
147 * @param string $hash Hash
151 protected function setHash($hash)